From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 78799396EC84 for ; Wed, 20 Jan 2021 18:51:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 78799396EC84 Received: by mail-pf1-x436.google.com with SMTP id o20so6655681pfu.0 for ; Wed, 20 Jan 2021 10:51:16 -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=KL8vGCX9tbXhaZZ4hk5FPLktq5r3dYE0NoZ/o8mBR6I=; b=X19iwqOwogmYUJomgvfbvFQ5Ud+kHAs5K6ZtRROsLlD1R09DdYrShD//7gviyxs8IR sPhv/YoXxwCHNER3mwusIF03LM7tHeZGwKckjmKAsGivBMB5Y7mRYB/lHTP000iMxgyt ZJECguht0I/3+9EZoE1SEnF36j5x5xdcKvCe8ooKIIkNeJlDDMYZUZjrpBnci6t+xXSA Dw/pdjMKnTq8eFrwuuApjAV6lS4sLk3AcO2TkCUt7juM6FeLRVQLwIfEp5h3PjP2wGdc tM0UCu2QKOBc8PiQ7ra3mh3F2cVdxzIUQdkWx8pCpqHFG5L4jQbcGb1u/dzUiFI+V5ig ZIyg== X-Gm-Message-State: AOAM5339PBiFqldJWZW1FoOXwbtkV6iFPrd/K5JUyu6UVEtOYkJDAzEw dP64fRoInDhMzkV91Jgp7r9G+RRyFOauQUsMI4O8oA== X-Google-Smtp-Source: ABdhPJwOaIoJSI58DnzsFqZAM1EN+bvW7joE8grsgxdVRsNZMLqY/h9Sk23kdWLApTNRe+aK8FuFOu5pRSvKBjsCEQg= X-Received: by 2002:aa7:8641:0:b029:1a1:e2f5:23de with SMTP id a1-20020aa786410000b02901a1e2f523demr9856169pfo.35.1611168675313; Wed, 20 Jan 2021 10:51:15 -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, 20 Jan 2021 10:51:04 -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" Cc: Florian Weimer , GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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: Wed, 20 Jan 2021 18:51:18 -0000 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 mal= loc.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 whi= ch > > > > would happen as a chain result: > > > > > > > > dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_si= ze > > > > __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_b= uffer_set_array_size.os) > > > > libc_pic.a(scratch_buffer_set_array_size.os) has an undefined fre= e > > > > 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___lib= c_fatal) > > > > >>> defined at libc_fatal.c > > > > >>> libc_fatal.os:(.text+0x240) in archive /tmp/p/glib= c/Release/libc_pic.a > > > > > > > > lld processes --defsym after all input files, so this trick does no= t > > > > suppress multiple definition errors with lld. Split the step into t= wo > > > > and use an object file to make the intention more obvious and make = lld > > > > work. > > > > > > > > This is conceptually more appropriate because --defsym defines a SH= N_ABS > > > > symbol while a normal definition is relative to the image base. > > > > > > > > > > This is irrelevant since --defsym was used to create a temporary fil= e 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-lin= ux/elf/librtld.map.o > > > -Wl,--defsym=3Dcalloc=3D0 -Wl,--defsym=3Dfree=3D0 -Wl,--defsym=3Dmall= oc=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-lin= ux/elf/dl-allobjs.os > > > /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-lin= ux/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-lin= ux/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 = 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)) $(pat= subst %,%:,$(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 becaus= e > > 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.