From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6CBE53890421; Mon, 1 Mar 2021 08:37:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CBE53890421 From: "i at maskray dot me" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: i at maskray dot me X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Mar 2021 08:37:27 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27492 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 #include 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=3D27451) % 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 comp= are -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 '__li= bc_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 GC= ed. (See "Metadata sections referenced by text sections" in http://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-ord= er ) 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/) --=20 You are receiving this mail because: You are on the CC list for the bug.=