From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id E41EB3861032 for ; Mon, 1 Feb 2021 13:46:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E41EB3861032 Received: by mail-ot1-x32a.google.com with SMTP id h14so16273704otr.4 for ; Mon, 01 Feb 2021 05:46:34 -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=9oJbQ3EGjgcWqF/MogWxtNi6zIWazU7v58FOpFVyDb0=; b=U5+yT2OJB7mG2n6D4wPKHmCW5f85iDbL+qdhafj71gS2YxNqMnSbIxOjAtM5LiTIXf DhPvuKeKv0iPwsM1AD/wxGCP/VGRX9NRVgrtVp3bVHB8QDjJR6nJOB0VXzukU2EXCZlR mIr4pNY11HqGuN0SgtDcncFpNfF+F6vvPY40ShGTH/PIMtz+PTjYlzgJoYa1SnvP81P5 GOhbAyqxs/IaYq0ZVQLO9FE051At8Dowgu4SHUIU08cwSFHcxASmN5vbg8rSw9t8EXuY lfqiZBPLOfWjvQPxgZvFp3H58u0exXfpALnMZgoej83zFGKV5kzkObqUi1QEYxhGq7y7 NyRw== X-Gm-Message-State: AOAM531p3w6f9yuja07IbMPRIIj8vwKU4ZcnuPUp8ZIbEBwY+oeGqUhD esNshyl3IEXPhcRp7gfd5cIPHdWmolsMBrj08AZMDdo/ X-Google-Smtp-Source: ABdhPJxfskzUBhf84LPG10qsyFhLWN7jMCPDgnLnLAF2Af1Q0IyKTmkDV3rvHHGHbb5GYBG2Xom5sAlSp1Pc4BRgqhk= X-Received: by 2002:a05:6830:1e2a:: with SMTP id t10mr12011701otr.90.1612187194234; Mon, 01 Feb 2021 05:46:34 -0800 (PST) MIME-Version: 1.0 References: <56de4bc0-05b1-49f9-32ce-b9eab7fdc510@linaro.org> <20210129192824.804615-1-maskray@google.com> <2d93f58d-64d2-cc71-1909-e08d486b2de8@linaro.org> In-Reply-To: <2d93f58d-64d2-cc71-1909-e08d486b2de8@linaro.org> From: "H.J. Lu" Date: Mon, 1 Feb 2021 05:45:58 -0800 Message-ID: Subject: Re: [PATCH v2] elf: Replace a --defsym trick with an object file to be compatible with LLD To: Adhemerval Zanella Cc: Fangrui Song , GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3037.1 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.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: Mon, 01 Feb 2021 13:46:36 -0000 On Mon, Feb 1, 2021 at 5:19 AM Adhemerval Zanella 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. -- H.J.