From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 3E74F3858D3C for ; Mon, 24 Jan 2022 03:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E74F3858D3C Received: by mail-pj1-x102e.google.com with SMTP id s61-20020a17090a69c300b001b4d0427ea2so19193084pjj.4 for ; Sun, 23 Jan 2022 19:50:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=1C0XooXmxPoak4aHZBWCjDjPyix6b4sD7vpTR8qDYcw=; b=jUGKimpztgsZHOcOmfUxsK8o6j/HG4DjSkWErTwUAK0aeeDJE4zG9QvwkjbEORvUFB OcSU4ix2lwf8YYYA/Wt377GMp3YkGfwWLY8yIadS/GUPRn8Ddmt2FZwOhgfU4jkNfTLh hMiKWHGHMUyWXwVEpZiNXWNVmtNK/vZnFDNgrO07LNrOKzcN+hqsm+9QztCcdIzIAPGh 3ixUX9MJz3xSSC/AT8MRQgvBmaBDKNeLP5mXE7nGc2qV2TusqFLmpptlJKIe9VnwUYhn 5xGukOe/rth4eKd4q/Fu3XvUyEThG6rZLY4Q+qFXnTclaXshf5uHRxGqALji7mKvB3LK s6Bg== X-Gm-Message-State: AOAM532/+CgyqTVoO+DzOdFXBhZnYhYTwo857jTkROUwbaQYFwnXSf6Y dz+y1wU+O/S5zUf4/rkZKVKXvHOw6GE= X-Google-Smtp-Source: ABdhPJzjVM28oH6ng8RRN2ipItXTDyA+Yal3BIyZG/GfYEITimyTozBGfkLHN/KQmQmoAFp6djrNsw== X-Received: by 2002:a17:902:76cb:b0:14b:24f:cc6e with SMTP id j11-20020a17090276cb00b0014b024fcc6emr12343348plt.17.1642996256362; Sun, 23 Jan 2022 19:50:56 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:6dcd:c685:dad8:6b5b]) by smtp.gmail.com with ESMTPSA id mz23sm11701304pjb.2.2022.01.23.19.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jan 2022 19:50:55 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id E06571140025; Mon, 24 Jan 2022 14:20:52 +1030 (ACDT) Date: Mon, 24 Jan 2022 14:20:52 +1030 From: Alan Modra To: libc-alpha@sourceware.org Cc: Tulio Magno Quites Machado Filho Subject: [PATCH 3/5] [PowerPC] Relocate stinfo->main Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 03:50:58 -0000 The previous 2 patches got us to the point of segfaulting when trying to transfer to main. start_addresses in sysdeps/powerpc/powerpc64/start.S is historical baggage that should disappear. Until someone does that, relocating stinfo->main by hand is one solution to the fact that the field may be unrelocated at the time it is accessed. This is similar to what is done for dynamic tags via the D_PTR macro. The makefile change is needed to pick up elf/dl-static-tls.h from dl-machine.h. diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile index fc7c29c695..93783cae00 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Makefile +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile @@ -27,3 +27,9 @@ tests += $(tests-static) tests += test-gettimebasefreq tests += test-powerpc-linux-sysconf endif + +ifeq ($(subdir),csu) +# to relocate stinfo->main +CPPFLAGS-libc-start.o += -I../elf +CPPFLAGS-libc-start.op += -I../elf +endif diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-start.c b/sysdeps/unix/sysv/linux/powerpc/libc-start.c index bb97d16145..8f0d3a0eac 100644 --- a/sysdeps/unix/sysv/linux/powerpc/libc-start.c +++ b/sysdeps/unix/sysv/linux/powerpc/libc-start.c @@ -23,6 +23,10 @@ #ifndef SHARED #include #endif +#if ENABLE_STATIC_PIE && !defined SHARED +/* For elf_machine_load_address. */ +#include +#endif /* The main work is done in the generic function. */ #define LIBC_START_MAIN generic_start_main @@ -95,8 +99,15 @@ __libc_start_main_impl (int argc, char **argv, __tcb_parse_hwcap_and_convert_at_platform (); #endif - return generic_start_main (stinfo->main, argc, argv, auxvec, - stinfo->init, stinfo->fini, rtld_fini, + void *main = stinfo->main; +#if ENABLE_STATIC_PIE && !defined SHARED + struct link_map *map = _dl_get_dl_main_map (); + if (!map->l_relocated) + main = (char *) main + elf_machine_load_address (); +#endif + + return generic_start_main (main, argc, argv, auxvec, + NULL, NULL, rtld_fini, stack_on_entry); } DEFINE_LIBC_START_MAIN_VERSION -- Alan Modra Australia Development Lab, IBM