From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id A3CD2387605F; Mon, 16 Mar 2020 16:01:54 +0000 (GMT) Received: by mail-oi1-x236.google.com with SMTP id x5so563969oic.13; Mon, 16 Mar 2020 09:01:54 -0700 (PDT) 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=rzlPkuz7attjblvp8nS5rgMtjS7Y/xMdpa6JMIOg5Ls=; b=c12jeyQyo8TVxSIOguEwvhU65rZWlQayoa7YHwvfhKHPgDzpqGaBmuZhEpz2sx1roO 3iBAAvVyJnX+38dOfri9pWivQuVFzGBIS4Qq8t+s7UhTG8jk+16qwXdeDzmTzEqc7r0A SgGIHDXobEjtO72OfNSu/57iBJw8o3cltKqX3bJeBaM1wGmOCqEbJ0u5NvqDo6Pb71mb qJZ71QLm/rHGV9A4fxoJ8z0qK2VfXSsAlynJ965DculPw/D5+MxRbT8Qi5UocokWNGS2 JooHRjDQN8UetmIZDgIxmkPvMccvGjt0CwsVtzz4dIRBckjVXjkQ1MBK5Cc7hAtwRQjn GKaA== X-Gm-Message-State: ANhLgQ3t6lj5dqUYMcreJfT1F8A3+68eaHzcZkcEXCxCa05cXwYJzCUi cUCXVZiVX7MjRGVZN/TK3eWNiwyaMk5KigwVqYg= X-Google-Smtp-Source: ADFU+vud2cvJVRlTZ4GSFXmnkZ5JRJtS2GG8R09tKn2sgUjMYbUHv+EeGmvq5Mx0A7Lm+1FIBl0Pb5VtlTsYfDr1Eow= X-Received: by 2002:aca:8ce:: with SMTP id 197mr162887oii.35.1584374513980; Mon, 16 Mar 2020 09:01:53 -0700 (PDT) MIME-Version: 1.0 References: <20200316045859.hq76yfsdqiupjgiy@google.com> <20200316050202.pql3syb2imduinf7@google.com> <20200316154706.fblgnhpezjggiugx@google.com> In-Reply-To: <20200316154706.fblgnhpezjggiugx@google.com> From: "H.J. Lu" Date: Mon, 16 Mar 2020 09:01:17 -0700 Message-ID: Subject: Re: Suppress the fetch of an archive member via --defsym (glibc/elf/librtld.map.o) To: Fangrui Song Cc: Binutils , GNU C Library , Florian Weimer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS 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, 16 Mar 2020 16:01:55 -0000 On Mon, Mar 16, 2020 at 8:47 AM Fangrui Song wrote: > > On 2020-03-16, H.J. Lu wrote: > >On Sun, Mar 15, 2020 at 10:02 PM Fangrui Song via Libc-alpha > > wrote: > >> > >> On 2020-03-15, Fangrui Song wrote: > >> >cd /tmp/p > >> >git clone git://sourceware.org/git/glibc.git; cd glibc > >> >mkdir Release; ../configure --prefix=3D/tmp/opt > >> >make -j > >> > > >> >When linking elf/librtld.map.o > >> > > >> >% gcc -nostdlib -nostartfiles -r -o /tmp/p/glibc/Release/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,-(' /tmp/p/glibc/Release/elf/dl-a= llobjs.os /tmp/p/glibc/Release/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/tmp/p/gl= ibc/Release/elf/librtld.mapT > >> > > >> >Without -Wl,defsym: > >> > > >> >dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size > >> >__libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffe= r_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_fat= al) > >> >>>>defined at dl-fxstatat64.c > >> >>>> /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fat= al) > >> >>>>defined at libc_fatal.c > >> >>>> libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Rel= ease/libc_pic.a > >> > > >> >glibc/elf/Makefile uses -Wl,--defsym=3D (rtld-stubbed-symbols) to sup= press libc_pic.a(malloc.os): > >> > > >> >% readelf -s elf/librtld.map.o | grep ABS | grep -v LOCAL > >> > 712: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __stack_ch= k_fail_local > >> > 826: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS malloc > >> > 876: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS __stack_ch= k_fail > >> > 905: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS calloc > >> > 975: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS realloc > >> > 1174: 0000000000000000 0 NOTYPE GLOBAL DEFAULT ABS free > >> > > >> >My question is: does the suppression via --defsym work reliably? > >> > > >> ># a.o > >> >call foo > >> > > >> ># b.a(b.o) > >> >.globl foo, free > >> >foo: > >> >free: > >> > > >> > > >> ># GNU ld --defsym is order dependent. > >> >ld.bfd a.o b.a --defsym foo=3D0 # b.a(b.o) is fetched. free is prese= nt > >> >ld.bfd --defsym foo=3D0 a.o b.a # b.a(b.o) is not fetched. free is a= bsent > >> > > >> ># gold --defsym is order independent. For the more complex glibc elf/= librtld.map.o case, it happens to match GNU ld. > >> >gold a.o b.a --defsym foo=3D0 # b.a(b.o) is not fetched. free is a= bsent > >> >gold --defsym foo=3D0 a.o b.a # b.a(b.o) is not fetched. free is a= bsent Gold is irrelevant here since it isn't supported to build glibc: https://sourceware.org/bugzilla/show_bug.cgi?id=3D24148 There are also other gold bugs which may impact glibc build. Please remov= e gold from this discussion. --=20 H.J.