From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 84F883858D3C for ; Mon, 24 Jan 2022 04:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 84F883858D3C Received: by mail-pj1-x1031.google.com with SMTP id d5so12826284pjk.5 for ; Sun, 23 Jan 2022 20:49:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eWdSBJMJvhRXFpF+8dPTBB5Y997v8+H6zsWWxaYa+pk=; b=2lmlVGsjofddkv9RPBGaVB9HYlom2dnW+UhU5Bj0WCrJ7d591opkc7vdUUkc3FRUhu SOXG0STcJiRV1T7wjmdpNo80qDQc/a7U50HGJo+iDAd+mwVfvW0yEw4OcqpL/gCfTX1O z3Y2XIM0tYY/L2XUaLvEZa4f6gz1Ix8P39KdaWwepmcCPwN/xHSjc1xzQ/5U38g8jAro CPK7LSEyVZABVigoJ3m5/GISum9qh/vkohIO5iE+DMe7f5PEeL13qYExgPIKJsbysuJb 2o29zvZR2H6rvLQbRDjy5mcq/JU2jMqp2ZIl2Q/03rj3mNPz9RW4wvCrXGoF28Hwko6m uSKw== X-Gm-Message-State: AOAM532+/qDjeDVqH7icJa4LT8iZZDEwH/CouXNv+urEHnkpgVzSDAWq siFUjLQoRXF+iOKHyFWX19SHMnFLbrPOtNpL1lU3hFD9 X-Google-Smtp-Source: ABdhPJy1UAIaFX+goGPWml2v38By712vKFK9prXMQsNKPR5loTJGxSYY3uxdndMef6LWxJM6U51Pd+Tg0ObV8MmubZE= X-Received: by 2002:a17:902:bf09:b0:149:d2a3:ddac with SMTP id bi9-20020a170902bf0900b00149d2a3ddacmr12995119plb.4.1642999760509; Sun, 23 Jan 2022 20:49:20 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Sun, 23 Jan 2022 20:48:44 -0800 Message-ID: Subject: Re: [PATCH 3/5] [PowerPC] Relocate stinfo->main To: Alan Modra Cc: GNU C Library , Tulio Magno Quites Machado Filho Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.7 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 04:49:24 -0000 On Sun, Jan 23, 2022 at 7:51 PM Alan Modra via Libc-alpha wrote: > > 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 Can you use __ehdr_start t here, similar to https://gitlab.com/x86-glibc/glibc/-/commit/1df93c500d0f81d30d1b7e323153512a8768bb72#ffb950808032d5085fdf882753d7bf8889e6a3d7 > + 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 -- H.J.