public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <maskray@google.com>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: Fangrui Song via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Makerules: Remove no-op -Wl,-d when linking libc_pic.os
Date: Mon, 27 Jun 2022 12:56:06 -0700	[thread overview]
Message-ID: <20220627195606.2bbe7kzbmztzsdoi@google.com> (raw)
In-Reply-To: <871qva353f.fsf@mid.deneb.enyo.de>

On 2022-06-27, Florian Weimer wrote:
>* Fangrui Song:
>
>>>Do you know what the .gnu.glibc-stub.* processing processing refers
>>>to?
>>
>> [a] Just few lines below, there is
>>
>>      # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
>>
>> The idea is to create libc_pic.os from libc_pic.a, strip .gnu.glibc-stub.*, then link libc_pic.os.clean into libc.so.
>>
>> Technically the relocatable link can be omitted.  We can change `build-shlib`
>> to link -Wl,--whole-archive libc_pic.a -Wl,--no-whole-archive instead.  objcopy -R works on an archive for
>> a long time.  I am unsure whether the 1990+ objcopy supports archives.
>> But at a first glance I do not find a good place to insert -Wl,--whole-archive into build-shlib...
>
>For linking libc.so, we can list the objects directly, then we don't
>need -Wl,--whole-archive.
>
>For linking ld.so, we do not use -Wl,--whole-archive because we
>actually want to link a subset.  I was under the impression that we
>rebuild objects for inclusion into ld.so, so I'm rather puzzled that
>we need this.

This plan looks good to me.
Removing the relocatable link for libc_pic.os will make incremental build slightly faster.

>> [b] Around $(objpfx)stubs: $(objs-for-stubs), we can see that
>> .gnu.glibc-stub.* is to generate */stubs files and finally testroot.root/$prefix/include/gnu/stubs-64.h
>>
>> % cat testroot.root/tmp/glibc/lld/include/gnu/stubs-64.h
>> /* This file is automatically generated.
>>     It defines a symbol `__stub_FUNCTION' for each function
>>     in the C library which is a stub, meaning it will fail
>>     every time called, usually setting errno to ENOSYS.  */
>>
>> #ifdef _LIBC
>>   #error Applications may not define the macro _LIBC
>> #endif
>>
>> #define __stub___compat_bdflush
>> #define __stub_chflags
>> #define __stub_fchflags
>> #define __stub_gtty
>> #define __stub_revoke
>> #define __stub_setlogin
>> #define __stub_sigreturn
>> #define __stub_stty
>
>Those warning sections must propagate into libc.so, so I think we
>could parse that and the generate header from it.

The final libc.so does not want .gnu.glibc-stub.* sections.  The current
build steps look like:

1. ar cruv libc_pic.a `cat csu/stamp.os iconv/stamp.os ...`
2. build libc_pic.os libc_pic.a
3. build libc_pic.os.clean from libc_pic.os
4. build libc.so from libc_pic.os.clean csu/abi-note.o elf/interp.os elf/ld.so ...

I think ideally 2 and 3 can be omitted.  It seems like you want to omit
libc_pic.a as well?  That looks good to me. stubs files can be either
generated from .os files (in step 1) or libc.so (then a separate strip
command on libc.so is needed).

      reply	other threads:[~2022-06-27 19:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26 18:40 Fangrui Song
2022-06-26 21:14 ` Florian Weimer
2022-06-26 22:29   ` Fangrui Song
2022-06-27  8:04     ` Florian Weimer
2022-06-27 19:56       ` Fangrui Song [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220627195606.2bbe7kzbmztzsdoi@google.com \
    --to=maskray@google.com \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).