Message ID | 20210129192824.804615-1-maskray@google.com |
---|---|
State | Committed |
Delegated to: | Adhemerval Zanella Netto |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> 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 2AC2538930E7; Fri, 29 Jan 2021 19:28:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AC2538930E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611948531; bh=Tmh+Bx2E6Tb/penoqG3vgr+CMGPb+fRCDV4l0cMtyHk=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fFr5xMoNPFWDShEQLlUgVJN0uPBqS/wbOFluwpvPpTZTBHhVNyO61Qf1XvJDOsdAP jVIAJE/9i63QCHCsKNiHnukh0LlY8hPZCkg/B9kkfyYNGWJYxoWHz7mSVV9eJ9Gz2Q QTX6wTJEb19R11bDAIdl234KmzNnk5I5E37XNK5g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id CBF2F3870854 for <libc-alpha@sourceware.org>; Fri, 29 Jan 2021 19:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CBF2F3870854 Received: by mail-yb1-xb49.google.com with SMTP id f127so11065715ybf.12 for <libc-alpha@sourceware.org>; Fri, 29 Jan 2021 11:28:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Tmh+Bx2E6Tb/penoqG3vgr+CMGPb+fRCDV4l0cMtyHk=; b=CFAHnFy03t3q6HdPSPwUZNaxhfAN5TdaVSwYy0Irb+nKnRZ82/5VyBK7+6oALum2s8 MpagomTrTtujZb1HQNF0cBuuA17tvV7HVILKjPD9rGij7r2NPbTzA/4JfdTLiHSMnSyU FXRwbb+YaOD8kL46M3fDhRj+Jq4xz+wPSGhyZO/5gU3T/nG++oKDp+MA42Eqqpj8C+ws f2XT/liAC+4CFpAoqHiOr+geDQCV1rdy/hklcocxTgWdPGs46u0PTqNBMa3jsiURwxej 7/128BgaDyDVnf/Q0D2Ou89SBs1VwV6fGJ7SAGP2JxrzR8w0ziwYhT79yPHmgZR7N8cv nCUw== X-Gm-Message-State: AOAM531R2Ber2U8ZM+FIGWJeGum6XLxe249EyQE47tGN9zni3I/GB5ru mdNADyR/uFpC4iMCXl+om0eHp1QX9MSdd5CB1Iy5e6Xtq1Zi+deQro3AiNIH86JzHrVyR07NWlN x2nhSB2u+38x4DoadumetipFTuQVChRqr/a9xPv4mCTyhV6DnIbRWY3hBbijUU3SfZn/P X-Google-Smtp-Source: ABdhPJze2KdQW/ArG9Slq5ZDA3fu9P4x9T9XwPMQwTaBJ0CxxILoGQlIRoZ7zNZ9iIfrxHI5BX1CBLz05HiS X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) (user=maskray job=sendgmr) by 2002:a25:6c05:: with SMTP id h5mr8162429ybc.450.1611948524257; Fri, 29 Jan 2021 11:28:44 -0800 (PST) Date: Fri, 29 Jan 2021 11:28:24 -0800 In-Reply-To: <56de4bc0-05b1-49f9-32ce-b9eab7fdc510@linaro.org> Message-Id: <20210129192824.804615-1-maskray@google.com> Mime-Version: 1.0 References: <56de4bc0-05b1-49f9-32ce-b9eab7fdc510@linaro.org> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v2] elf: Replace a --defsym trick with an object file to be compatible with LLD To: libc-alpha@sourceware.org, Adhemerval Zanella <adhemerval.zanella@linaro.org> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-19.9 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Fangrui Song via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Fangrui Song <maskray@google.com> Cc: Fangrui Song <maskray@google.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
[v2] elf: Replace a --defsym trick with an object file to be compatible with LLD
|
|
Commit Message
Fangrui Song
Jan. 29, 2021, 7:28 p.m. UTC
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. See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html for discussions about the --defsym semantics. This commit is available on https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/lld --- elf/Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
Comments
On 29/01/2021 16:28, Fangrui Song 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. > > See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html > for discussions about the --defsym semantics. > > This commit is available on https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/lld > --- > elf/Makefile | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/elf/Makefile b/elf/Makefile > index 5d666b1b0c..03e4034cc7 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -526,10 +526,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. > @@ -538,9 +534,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 > + printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \ > + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - > + $(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. Looks ok, I haven't see any build issue. The '=' seems unrequired, although '=' seems to work on all supported architectures (HAVE_ASM_SET_DIRECTIVE does not seem to be necessary to handle here). It is ok for 2.34 from my side. H.J, do you see any issues of not setting the symbol to '0'?
* Fangrui Song via Libc-alpha: > $(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 > + printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \ > + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - > + $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T > + rm -f %@T.o $@.o > mv -f $@T $@ It may be a little bit cleaner to replace the shell/make mix with just shell, like (untested): for symbol in $(rtld-stubbed-symbols) ; do \ echo ".globl $$symbol" ; \ echo "$$symbol:" ; \ done | $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - Thanks, Florian
On Mon, Feb 1, 2021 at 5:19 AM Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote: > > > > On 29/01/2021 16:28, Fangrui Song 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. > > > > See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html > > for discussions about the --defsym semantics. > > > > This commit is available on https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/lld > > --- > > elf/Makefile | 11 ++++------- > > 1 file changed, 4 insertions(+), 7 deletions(-) > > > > diff --git a/elf/Makefile b/elf/Makefile > > index 5d666b1b0c..03e4034cc7 100644 > > --- a/elf/Makefile > > +++ b/elf/Makefile > > @@ -526,10 +526,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. > > @@ -538,9 +534,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 > > + printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \ > > + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - > > + $(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. > > Looks ok, I haven't see any build issue. The '=' seems unrequired, although '=' > seems to work on all supported architectures (HAVE_ASM_SET_DIRECTIVE does not > seem to be necessary to handle here). > > It is ok for 2.34 from my side. H.J, do you see any issues of not setting the > symbol to '0'? LGTM. Thanks.
diff --git a/elf/Makefile b/elf/Makefile index 5d666b1b0c..03e4034cc7 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -526,10 +526,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. @@ -538,9 +534,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 + printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \ + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - + $(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.