public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "i at maskray dot me" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/27492] New: Make static linking friendly with {ld.bfd,ld.lld} -z start-stop-gc: removing unused section '__libc_atexit'
Date: Mon, 01 Mar 2021 08:37:27 +0000	[thread overview]
Message-ID: <bug-27492-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=27492

            Bug ID: 27492
           Summary: Make static linking friendly with {ld.bfd,ld.lld} -z
                    start-stop-gc: removing unused section '__libc_atexit'
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: i at maskray dot me
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

#include <stdio.h>
#include <stdlib.h>

void hook() {
  puts("hello");
}
int main() {
  atexit(hook);
}

// Require -z start-stop-gc, which is available in trunk ld.lld
(https://reviews.llvm.org/D96914) and GNU ld newer than 2021-03-01
(https://sourceware.org/bugzilla/show_bug.cgi?id=27451)
% gcc -static a.c -Wl,--gc-sections -z start-stop-gc
% ./a.out
hello

This appears to work. However, if you use the approach in
https://sourceware.org/pipermail/binutils/2021-February/115561.html to compare
-z nostart-stop-gc and -z start-stop-gc output,
you should notice a difference

% diff 0 1
16a17
> /home/ray/Dev/binutils-gdb/Debug/ld/ld-new: removing unused section '__libc_atexit' in file 'usr/lib/x86_64-linux-gnu/libc.a(genops.o)'


I don't know whether the difference matters. In 2010, this difference caused
bug 11133.
A GNU ld workaround was installed.
Then in 2015-10, the "__start_xx reference from a live input section retain all
xx sections" rule was extended to all translation units.
This is unfortunate because many modern metadata section usage cannot be GCed.
(See "Metadata sections referenced by text sections" in
http://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order )


If __libc_atexit wants to be a GC root, use SHF_GNU_RETAIN;
otherwise, use an artificial relocation like R_X86_64_NONE (see
https://lwn.net/Articles/741494/)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2021-03-01  8:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01  8:37 i at maskray dot me [this message]
2021-03-01 13:54 ` [Bug libc/27492] " fweimer at redhat dot com
2021-03-02  5:16 ` i at maskray dot me
2021-04-17  3:09 ` i at maskray dot me

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=bug-27492-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).