From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id ADFB03857836 for ; Tue, 19 Jan 2021 08:50:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ADFB03857836 Received: by mail-pl1-x62c.google.com with SMTP id s15so10103674plr.9 for ; Tue, 19 Jan 2021 00:50:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nh61FJWs2TL5O7txNsg63SVaYzQCe0px6iwnxK9eJec=; b=ql3MPlxgGNj0iJ03UQMwyCCVRwb3KngXSMnFtDFOvZUk+5Wm/MARKpxPQt14FIfodc j83Wo2O/E/dTvWAiDJLLDrr5MWO5lHzAu7sn4BNewwUxpAblUqOjcVR7/TNsrhVx1pTE sMA6XvM2tAmzBdaQV50mgwP/THSsv+kCTVfhO56Qzgg551ras7BJKL515NKoN7v70YSX 1ItGOMoE0pT1FN8jpTFmieB0qu063JyfTtOFaiViW9TUZBEC+MEW6eovkbRnzk8iaIHP W45jSBk7q1OvoExBbcFEGvZMCjr20Hs3pvVKHDCjCLBfiqvx8lpM+w9UiyV04sXmVoBx Axeg== X-Gm-Message-State: AOAM530f78M95NbKzPCVoevJVi7eXK9XFLRINwOC+2FFkHhz0HjPKrcG 10GKoHuHWrJLMsNdX0qvTAVgIZTFPnpRpAd0qSVdYw== X-Google-Smtp-Source: ABdhPJwxoSXSbjQwHEPp//4Q2joyl/U8/KC1/13+Kx3LEhN9dkleINGs/Cor78v081cpXi9WaO2LJJnURLIfA/q0xog= X-Received: by 2002:a17:902:d50d:b029:de:5b13:498d with SMTP id b13-20020a170902d50db02900de5b13498dmr3769825plg.38.1611046240657; Tue, 19 Jan 2021 00:50:40 -0800 (PST) MIME-Version: 1.0 References: <20201228194855.510315-1-maskray@google.com> <20201228194855.510315-3-maskray@google.com> In-Reply-To: From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Tue, 19 Jan 2021 00:50:29 -0800 Message-ID: Subject: Re: [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld To: "H.J. Lu" , Florian Weimer Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-25.6 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, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 19 Jan 2021 08:50:43 -0000 On Mon, Jan 18, 2021 at 4:04 PM H.J. Lu wrote: > > On Mon, Dec 28, 2020 at 11:50 AM Fangrui Song via Libc-alpha > wrote: > > > > The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os > > definitions before libc_pic.a so that libc_pic.a(malloc.os) is not > > fetched. This trick is used to avoid multiple definition errors which > > would happen as a chain result: > > > > dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size > > __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os) > > libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free > > free fetches libc_pic.a(malloc.os) > > libc_pic.a(malloc.os) has an undefined __libc_message > > __libc_message fetches libc_pic.a(libc_fatal.os) > > > > libc_fatal.os will cause a multiple definition error (__GI___libc_fatal) > > >>> defined at dl-fxstatat64.c > > >>> /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal) > > >>> defined at libc_fatal.c > > >>> libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a > > > > lld processes --defsym after all input files, so this trick does not > > suppress multiple definition errors with lld. Split the step into two > > and use an object file to make the intention more obvious and make lld > > work. > > > > This is conceptually more appropriate because --defsym defines a SHN_ABS > > symbol while a normal definition is relative to the image base. > > > > This is irrelevant since --defsym was used to create a temporary file which was > removed immediately after it was created: > > /usr/bin/gcc -nostdlib -nostartfiles -r -o > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map.o > -Wl,--defsym=calloc=0 -Wl,--defsym=free=0 -Wl,--defsym=malloc=0 > -Wl,--defsym=realloc=0 -Wl,--defsym=__stack_chk_fail=0 > -Wl,--defsym=__stack_chk_fail_local=0 \ > '-Wl,-(' > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/dl-allobjs.os > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/libc_pic.a > -lgcc '-Wl,-)' -Wl,-Map,/export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.mapT > rm -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map.o > mv -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.mapT > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map > > > --- > > elf/Makefile | 11 ++++------- > > 1 file changed, 4 insertions(+), 7 deletions(-) > > > > diff --git a/elf/Makefile b/elf/Makefile > > index 0b4d78c874..299bf24b49 100644 > > --- a/elf/Makefile > > +++ b/elf/Makefile > > @@ -524,10 +524,6 @@ rtld-stubbed-symbols = \ > > malloc \ > > realloc \ > > > > -# The GCC arguments that implement $(rtld-stubbed-symbols). > > -rtld-stubbed-symbols-args = \ > > - $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols)) > > - > > ifeq ($(have-ssp),yes) > > # rtld is not built with the stack protector, so these references will > > # go away in the rebuilds. > > @@ -536,9 +532,10 @@ endif > > > > $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a > > @-rm -f $@T > > - $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \ > > - '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T > > - rm -f $@.o > > + echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \ > > + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - > > Please generate > > .globl symbol; > symbol = 0; > > to make it closer to -Wl,--defsym=symbol=0. If symbol: and symbol = 0; work, isn't symbol: slightly better because it looks more normal? Or is the intention here using SHN_ABS to make it clear these symbols are special? > > + $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T > > + rm -f %@T.o $@.o > > mv -f $@T $@ > > > > # For lld, skip preceding addresses and values before matching the archive and the member. > > -- > > 2.29.2.729.g45daf8777d-goog > > > > > -- > H.J.