From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by sourceware.org (Postfix) with ESMTPS id BC9DB3857410 for ; Sun, 26 Jun 2022 22:29:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BC9DB3857410 Received: by mail-pj1-x102f.google.com with SMTP id l2so6374794pjf.1 for ; Sun, 26 Jun 2022 15:29:41 -0700 (PDT) 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=6TGuz3M94I5bKhaIrgFYwIq4WUVS5K9+scuTI2FATJg=; b=h9qvg9MplUSGWZHOnCtWqZ++pyJZFYg/2BaByX+khO7+RfFrgSchLIPzSF+NfLR+OS CBKvLXBnbAhgma3X4FOWbs1l/ucvwz/+j5c+YvHQln+FkGzFJXlGbaGDVfm92Jzg0tPR rp/Ih+06YVz5n997EQZGv/C3nce4GTqdLjajBtKUlm3scXRNywQwU/C20rkkLXlyVqiH FedsQ5eyYO/EyMrt0SeW99gZ05EVxexJHZgbvjq6EK7SJDJjzvy3c3wyVxK664OQEjya v4evT+NMtjQDdylkij+R9Sda1yTggIIiZQpNTna3qKhtx2CeslkUv69fEKzgGskkSpZE a6/g== X-Gm-Message-State: AJIora83uSSFdpZ//Zqh0jW+TYyn+LNGZ+HEHbBMWTk/gcdF08770vTF 8ugajdLHrLUbBwVJUIboesyznaQrXn2KxA== X-Google-Smtp-Source: AGRyM1ueHbbx4s8BycbEGkyDp0hpmK+reE5HLsiupG0FhN7dE8DLGs68h2dhq7R9CfpGc+mv7PaX7w== X-Received: by 2002:a17:90a:e7ca:b0:1ed:3b4e:bee5 with SMTP id kb10-20020a17090ae7ca00b001ed3b4ebee5mr11650770pjb.108.1656282580577; Sun, 26 Jun 2022 15:29:40 -0700 (PDT) Received: from google.com ([2620:15c:2ce:200:9485:9ff1:9144:d14a]) by smtp.gmail.com with ESMTPSA id 33-20020a630d61000000b0040d1eb90d67sm5557827pgn.93.2022.06.26.15.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 15:29:40 -0700 (PDT) Date: Sun, 26 Jun 2022 15:29:36 -0700 From: Fangrui Song To: Florian Weimer Cc: Fangrui Song via Libc-alpha Subject: Re: [PATCH] Makerules: Remove no-op -Wl,-d when linking libc_pic.os Message-ID: <20220626222936.56qfdvvtbv4u7gz2@google.com> References: <20220626184025.553459-1-maskray@google.com> <87tu87nn4y.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <87tu87nn4y.fsf@mid.deneb.enyo.de> X-Spam-Status: No, score=-26.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sun, 26 Jun 2022 22:29:43 -0000 On 2022-06-26, Florian Weimer wrote: >* Fangrui Song via Libc-alpha: > >> In GNU ld, -d assigns space to common symbols for -r (i.e. change common >> symbols to STB_GLOBAL definitions). This option was added in commit >> da2d1bc5adf49352232ad0514e79fbd5dcae08e8 (1998) likely because ld at >> that time had a bug that common symbols did not override shared object >> definitions. -d has been long unneeded and more so since -fno-common >> was added to +cflags. >> --- >> Makerules | 8 ++------ >> 1 file changed, 2 insertions(+), 6 deletions(-) >> >> diff --git a/Makerules b/Makerules >> index dfe89e9e39..d1e139d03c 100644 >> --- a/Makerules >> +++ b/Makerules >> @@ -633,14 +633,10 @@ LDFLAGS-c.so = -nostdlib -nostartfiles >> LDLIBS-c.so += $(libc.so-gnulib) >> # Give libc.so an entry point and make it directly runnable itself. >> LDFLAGS-c.so += -e __libc_main >> -# Pre-link the objects of libc_pic.a so that we can locally resolve >> -# COMMON symbols before we link against ld.so. This is because ld.so >> -# contains some of libc_pic.a already, which will prevent the COMMONs >> -# from being allocated in libc.so, which introduces evil dependencies >> -# between libc.so and ld.so, which can make it impossible to upgrade. >> +# Pre-link the objects of libc_pic.a for .gnu.glibc-stub.* processing. >> $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a >> $(LINK.o) -nostdlib -nostartfiles -r -o $@ \ >> - $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@ >> + $(LDFLAGS-c_pic.os) $(whole-archive) $^ -o $@ >> >> ifeq (,$(strip $(shlib-lds-flags))) >> # Generate a list of -R options to excise .gnu.glibc-stub.* sections. > >This looks okay to me, thanks. > >Do you know what the .gnu.glibc-stub.* processing processing refers >to? [a] Just few lines below, there is # Generate a list of -R options to excise .gnu.glibc-stub.* sections. The idea is to create libc_pic.os from libc_pic.a, strip .gnu.glibc-stub.*, then link libc_pic.os.clean into libc.so. Technically the relocatable link can be omitted. We can change `build-shlib` to link -Wl,--whole-archive libc_pic.a -Wl,--no-whole-archive instead. objcopy -R works on an archive for a long time. I am unsure whether the 1990+ objcopy supports archives. But at a first glance I do not find a good place to insert -Wl,--whole-archive into build-shlib... [b] Around $(objpfx)stubs: $(objs-for-stubs), we can see that .gnu.glibc-stub.* is to generate */stubs files and finally testroot.root/$prefix/include/gnu/stubs-64.h % cat testroot.root/tmp/glibc/lld/include/gnu/stubs-64.h /* This file is automatically generated. It defines a symbol `__stub_FUNCTION' for each function in the C library which is a stub, meaning it will fail every time called, usually setting errno to ENOSYS. */ #ifdef _LIBC #error Applications may not define the macro _LIBC #endif #define __stub___compat_bdflush #define __stub_chflags #define __stub_fchflags #define __stub_gtty #define __stub_revoke #define __stub_setlogin #define __stub_sigreturn #define __stub_stty