From patchwork Mon Feb 28 06:40:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 51421 X-Patchwork-Delegate: tuliom@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A06343858434 for ; Mon, 28 Feb 2022 06:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A06343858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646030646; bh=5cVFRMeJt1caFkOpQHebhUyKRE38nCtKWvxc/gPYdjU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=TdDvM/aL/27CIRyIwxawe1HH98ndhm5hJQH9TrXpqa9Wn0fUIt22WRblDW6aZS1mQ SRXGQE0XdnXdZKVR5UtMP4Xdze5m4vYEJM94+isAwuuu8Nf/NqwkR/08Eos9t426ui 1GT/5uhngRPIqVj+dLVNrH9sZ7nHNKpRCfs+VpuA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id BD79C3858430 for ; Mon, 28 Feb 2022 06:41:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD79C3858430 Received: by mail-pf1-x42f.google.com with SMTP id i21so10184834pfd.13 for ; Sun, 27 Feb 2022 22:41:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5cVFRMeJt1caFkOpQHebhUyKRE38nCtKWvxc/gPYdjU=; b=S5RtHjm1QASsMOxEkXKWfau15PSCmHm1UzfYRUMXNsHTFeOVYYnEQbGwe0R6ht+Jum HXUxU1YYS8OYVnkWnUGOyg1zqdZZt3lwal11Egpx/md3fDsElBh9TRsW2bfqPK1xp/wZ JqAzdX/OpMZ3giDsg5DXXuHab9wwhdWonkcD697nne1uMatFIRZO3JR1lQocUeMO29cZ mo4b6ZCd3RzepQtt/KadIRFPbKE4fwCUjC6rNeinKuNvziKyQ3D7+SH4gwnYy3TV4oAH aZn6RMC4UWyIX0Vi50j+x86V3B0sJcgsztnMDVgnDR6/Wl3SJYzRDfigC8KvJMiZRWGO dhJg== X-Gm-Message-State: AOAM532E6xun0K7AgKlJ8YZYL72fD1nwdVdjx85LHeZVMHh+w9478Gqo Sv6sIJq59yWQ2cYYV2AwFbldDxOGVbU= X-Google-Smtp-Source: ABdhPJx67g+AXYOogHIxWDd+fvkRU3OqDDNHkKi1kaDXwnf+fT4fWU2vzS8k0TJP12x+ZAMSpJZ7DA== X-Received: by 2002:a05:6a00:1310:b0:4ca:cc46:20c7 with SMTP id j16-20020a056a00131000b004cacc4620c7mr19893250pfu.44.1646030503599; Sun, 27 Feb 2022 22:41:43 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:f31d:e338:6c7b:8cfa]) by smtp.gmail.com with ESMTPSA id q15-20020a63504f000000b0037425262293sm9130249pgl.43.2022.02.27.22.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 22:41:42 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 3/4] powerpc: Relocate stinfo->main Date: Mon, 28 Feb 2022 17:10:51 +1030 Message-Id: <20220228064052.3413334-4-amodra@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220228064052.3413334-1-amodra@gmail.com> References: <20220228064052.3413334-1-amodra@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3036.6 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, T_SCC_BODY_TEXT_LINE 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-Patchwork-Original-From: Alan Modra via Libc-alpha From: Alan Modra Reply-To: Alan Modra Cc: Tulio Magno Quites Machado Filho , Alan Modra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. stinfo->init and stinfo->fini are zero in both powerpc64/start.S and powerpc32/start.S, so make it a little more obvious they are unused by passing NULLs to LIBC_START_MAIN. The makefile change is needed to pick up elf/dl-static-tls.h from dl-machine.h. Reviewed-by: Tulio Magno Quites Machado Filho 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