From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 0E36F384647C for ; Thu, 28 Jan 2021 01:04:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0E36F384647C Received: by mail-pl1-x62a.google.com with SMTP id s15so2351839plr.9 for ; Wed, 27 Jan 2021 17:04:08 -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=851wgDxvmpXDBFcY9JDNEuS1GgkaTwVp9MUYlkC3DVg=; b=nCFXukFBl4iWQNh7qsRGbaF7NvpIAa7d3QHmk4wXm2LLk3O6V7XWBWUxFdIlxvBkfR BbdFKHWQ/W1g4IN8IQFBUdODY8VB61qQGpeH6BVDAJNNqC2DvT/pNQAUfSfnosVsP+mk oUMJC1cPA1VOKV0K9J6nh7sy12SlBTyyNy5IVqBIRxsEYTU3UF3hZe4apwf8iXoTrvVv AQwLt8r8MtMUfNHGjVRIabJt/6DM1Jvt1iY/wG4Xn5puPwewytiKre2krkFcAGZURPVe mtnO61MlxoFCjyOX3xIFXBZd1c9Ma4EhW+57VhiP6b9yPOTSMVqKUNwWxlzIBee8bVmm B8IA== X-Gm-Message-State: AOAM5329xQnqQIiFDEBUt0zT2Ivc+sZOeFKre3b2ZRt0YBpxsyE3a0KS jx1KJYvxkfXdYLncU3BBnRQcyCMcI16YL4MBxOt2Nw== X-Google-Smtp-Source: ABdhPJw75bSn8/yoSGKbBmNmEoRpe18LDsgXsqrNZJtNMLYXXnijuNymLgXa+kafBisW7AvhtbLsRl9XZ1mBGPGwnK4= X-Received: by 2002:a17:90a:da02:: with SMTP id e2mr8419413pjv.173.1611795846922; Wed, 27 Jan 2021 17:04:06 -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: Wed, 27 Jan 2021 17:03:55 -0800 Message-ID: Subject: Re: [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld To: Florian Weimer Cc: "H.J. Lu" , GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-24.9 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: Thu, 28 Jan 2021 01:04:10 -0000 On Wed, Jan 20, 2021 at 10:51 AM F=C4=81ng-ru=C3=AC S=C3=B2ng wrote: > > On Tue, Jan 19, 2021 at 4:31 AM H.J. Lu wrote: > > > > 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 m= alloc.os > > > > > definitions before libc_pic.a so that libc_pic.a(malloc.os) is no= t > > > > > fetched. This trick is used to avoid multiple definition errors w= hich > > > > > 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 f= ree > > > > > 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___li= bc_fatal) > > > > > >>> defined at dl-fxstatat64.c > > > > > >>> /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___l= ibc_fatal) > > > > > >>> defined at libc_fatal.c > > > > > >>> libc_fatal.os:(.text+0x240) in archive /tmp/p/gl= ibc/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 mak= e 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 f= ile 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-l= inux/elf/librtld.map.o > > > > -Wl,--defsym=3Dcalloc=3D0 -Wl,--defsym=3Dfree=3D0 -Wl,--defsym=3Dma= lloc=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-l= inux/elf/dl-allobjs.os > > > > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-l= inux/libc_pic.a > > > > -lgcc '-Wl,-)' -Wl,-Map,/export/users/hjl/build/gnu/tools-build/gli= bc-gitlab/build-x86_64-linux/elf/librtld.mapT > > > > rm -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x8= 6_64-linux/elf/librtld.map.o > > > > mv -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x8= 6_64-linux/elf/librtld.mapT > > > > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-l= inux/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-symbo= ls)) > > > > > - > > > > > ifeq ($(have-ssp),yes) > > > > > # rtld is not built with the stack protector, so these reference= s will > > > > > # go away in the rebuilds. > > > > > @@ -536,9 +532,10 @@ endif > > > > > > > > > > $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)lib= c_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)) $(p= atsubst %,%:,$(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 beca= use > > > 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". > > > > -- > > H.J. > > Thanks for the tip. In this case I think the patch as is (sticking > with `foo:`, don't use `foo =3D 0` or set) is better. > foo: works everywhere. Ping. I think the patch as-is is better than the alternative approach using either `=3D` or `.set`.