From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 0F3923858002 for ; Tue, 19 Jan 2021 12:31:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0F3923858002 Received: by mail-oi1-x22a.google.com with SMTP id h192so3281932oib.1 for ; Tue, 19 Jan 2021 04:31:15 -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:content-transfer-encoding; bh=WHl8nfNqSlF8JTad7EffaIw09QpJnsPGWuj3TnbjSEY=; b=slGa8Ejt2Drrhwhgdzd6ZY2Z4QAoZnUHUr+7lcvPZ9AzooVkmjLxvsz99W0c++yGUc xmSjA6wC9PNkbXBUH0ygqyveYIkU+QKLMFHcZQdworzUrSK7NwsC2q6jooDzGVoqD0VT O2kFAAHHTSG7SVP967XyOzgJCg7kN7uGyzK9H7cyALomJp3cdelD6FKkfzRN4uRLX4LI w8kbh7Gke++BYA1pa2qyaldqU4KLXHycDEqycfehMwqoWq/Yz0Q21JV0TRRiaLfQvuQ8 V1ZzjKgkFWosFr5zdNugcai1EPW6dYmAr+cADMfDvSRvPew7Eo4XydgoWIiu6g30gs5p Trwg== X-Gm-Message-State: AOAM533GfKVoNCxYu0HQQtQomj0/2mmfPEODqZMSTpMfafPLCitVYYTr hExpVQLw9abAUFhb+xeN4r0lG8VggYXLI+GI3cQ= X-Google-Smtp-Source: ABdhPJxRzYpBvq7IVeT3kElr7vTnrnh/Kw2U26q/2OMAyfzDkeYad5w3AKYQ+CsK0Jc2RJ3xTMq1mjBAYpAWNC0Q9B4= X-Received: by 2002:aca:c693:: with SMTP id w141mr2335164oif.58.1611059474501; Tue, 19 Jan 2021 04:31:14 -0800 (PST) MIME-Version: 1.0 References: <20201228194855.510315-1-maskray@google.com> <20201228194855.510315-3-maskray@google.com> In-Reply-To: From: "H.J. Lu" Date: Tue, 19 Jan 2021 04:30:38 -0800 Message-ID: Subject: Re: [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld To: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Cc: Florian Weimer , GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3036.4 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: Tue, 19 Jan 2021 12:31:17 -0000 On Tue, Jan 19, 2021 at 12:50 AM F=C4=81ng-ru=C3=AC S=C3=B2ng wrote: > > 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=3Dmalloc=3D0 and other mallo= c.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_buf= fer_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_f= atal) > > > >>> 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 ll= d > > > 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=3Dcalloc=3D0 -Wl,--defsym=3Dfree=3D0 -Wl,--defsym=3Dmalloc= =3D0 > > -Wl,--defsym=3Drealloc=3D0 -Wl,--defsym=3D__stack_chk_fail=3D0 > > -Wl,--defsym=3D__stack_chk_fail_local=3D0 \ > > '-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-g= itlab/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 =3D \ > > > malloc \ > > > realloc \ > > > > > > -# The GCC arguments that implement $(rtld-stubbed-symbols). > > > -rtld-stubbed-symbols-args =3D \ > > > - $(patsubst %,-Wl$(comma)--defsym=3D%=3D0, $(rtld-stubbed-symbols)) > > > - > > > ifeq ($(have-ssp),yes) > > > # rtld is not built with the stack protector, so these references wi= ll > > > # go away in the rebuilds. > > > @@ -536,9 +532,10 @@ endif > > > > > > $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pi= c.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)) $(patsu= bst %,%:,$(rtld-stubbed-symbols))' | \ > > > + $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - > > > > Please generate > > > > .globl symbol; > > symbol =3D 0; > > > > to make it closer to -Wl,--defsym=3Dsymbol=3D0. > > If symbol: and symbol =3D 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? Generate machine independent assembly codes is tricky. We should make before and after the change as close as possible to avoid ANY surprises. BTW, you need to check HAVE_ASM_SET_DIRECTIVE to decide using ".set" vs "=3D". --=20 H.J.