From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 9014E3857820 for ; Fri, 29 Jan 2021 15:30:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9014E3857820 Received: by mail-oi1-x231.google.com with SMTP id m13so10206710oig.8 for ; Fri, 29 Jan 2021 07:30:01 -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=AHzHPChMZQS5G4ONnfdtMyr3LYzj/H9kwo+LKrUj9NI=; b=nj37MunI1K/z637n1PwaHKg7VoGqzOZCkHbIYE71Ev38dhOIfWq+BBoG61OSm0nl5m PbHkGTirWC6uVTZScH1QpVPcSZclFst7L085ZhiRwtPBKqQzKnALdEnIDfw72swnG6Dx S0O/wDHi4iOMISTlRICPWhz8Yps3I6zgCRFGeaw4RF0HrkzSWH96eaYIlFdVwL6UsaVl YYoDaWTCBuQHJ8RArLZpYU45q8Ybf8Ew+8usB+qTAVcRXlqWNUGaQ3wQXc6xoEjBymaz mB1Pnv2P9y1+voPBYJEDpc2azXtqJTWbWIX9w+ArNDD5U+o66WOu/W+BizWUS4ueiJGN V3Eg== X-Gm-Message-State: AOAM531au7xWfv+WLe5mZmF1LlONIa8c5r3wL4CketqHWAKlL8vMHmvQ biY+vCRMhcxymcm+CF1VYCeAOcee2yBYugE1GlU= X-Google-Smtp-Source: ABdhPJyP6tqTsw+RNZy7srF401WKhPrSisiMiagmts4pnabKYIItRuWhCVtbS3lVEKBuYzfgZnu6ClnNU/y+YxdwX68= X-Received: by 2002:a05:6808:101:: with SMTP id b1mr2922460oie.25.1611934200907; Fri, 29 Jan 2021 07:30:00 -0800 (PST) MIME-Version: 1.0 References: <20201228194855.510315-1-maskray@google.com> <20201228194855.510315-3-maskray@google.com> <4c4b4d3b-6265-7575-d1e8-879471121511@linaro.org> In-Reply-To: <4c4b4d3b-6265-7575-d1e8-879471121511@linaro.org> From: "H.J. Lu" Date: Fri, 29 Jan 2021 07:29:24 -0800 Message-ID: Subject: Re: [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld To: Adhemerval Zanella Cc: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= , Florian Weimer , GNU C Library Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3036.8 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: Fri, 29 Jan 2021 15:30:03 -0000 On Fri, Jan 29, 2021 at 7:26 AM Adhemerval Zanella via Libc-alpha wrote: > > > > On 27/01/2021 22:03, F=C4=81ng-ru=C3=AC S=C3=B2ng via Libc-alpha wrote: > > 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 ma= lloc.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 wh= ich > >>>>>> would happen as a chain result: > >>>>>> > >>>>>> dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_s= ize > >>>>>> __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 fr= ee > >>>>>> 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___lib= c_fatal) > >>>>>> >>> defined at dl-fxstatat64.c > >>>>>> >>> /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___li= bc_fatal) > >>>>>> >>> defined at libc_fatal.c > >>>>>> >>> libc_fatal.os:(.text+0x240) in archive /tmp/p/gli= bc/Release/libc_pic.a > >>>>>> > >>>>>> lld processes --defsym after all input files, so this trick does n= ot > >>>>>> 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 S= HN_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-symbol= s)) > >>>>>> - > >>>>>> 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)) $(pa= tsubst %,%:,$(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 bec= ause > >>>> it looks more normal? > >>>> Or is the intention here using SHN_ABS to make it clear these symbol= s > >>>> 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`. > > The patch breaks both arc-linux-gnuhf and hppa-linux-gnu with recent > ld.bfd 2.26, as below. > > We will need to sort these out. > Does my suggestion work? --=20 H.J.