[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/18379] New: .fini_array support brings in unused codes
From: |
hjl.tools at gmail dot com |
Subject: |
[Bug ld/18379] New: .fini_array support brings in unused codes |
Date: |
Tue, 05 May 2015 20:04:14 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=18379
Bug ID: 18379
Summary: .fini_array support brings in unused codes
Product: binutils
Version: 2.26 (HEAD)
Status: NEW
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
To support .fini_array, linker always links in the .fini_array handler
even if it isn't used. We can't mark the .fini_array handler weak since
it won't be called when it is used:
address@hidden fini]$ cat foo.c
static void foo ( void ) __attribute__((destructor));
static int counter;
static void
foo (void)
{
counter++;
}
address@hidden fini]$ cat start.c
extern void __libc_csu_fini (void)
#ifdef WEAK
__attribute__((weak))
#endif
;
void
_start ()
{
#ifdef WEAK
if (__libc_csu_fini)
#endif
__libc_csu_fini ();
}
address@hidden fini]$ cat fini.c
#include <stdint.h>
#include <stddef.h>
extern void (*__fini_array_start[]) (void);
extern void (*__fini_array_end[]) (void);
static void
run_fini_arry (void *p)
{
uintptr_t i = (uintptr_t) p;
while (i-- > 0)
(*__fini_array_start [i]) ();
}
extern void bar (void (*fn) (void *), void *arg, void *handle);
void
__libc_csu_fini (void)
{
ptrdiff_t count = __fini_array_end - __fini_array_start;
if (count)
bar ((void (*) (void *)) run_fini_arry, (void *) count, NULL);
}
address@hidden fini]$ cat bar.S
.section .text.bar,"ax",@progbits
.globl bar
.type bar, @function
bar:
.space 0x400000
.size bar, .-bar
address@hidden fini]$ make LD=ld
gcc -O2 -g -c -o start.o start.c
ld -o x start.o libbar.a
gcc -O2 -g -DWEAK -c start.c -o startweak.o
gcc -O2 -g -fpic -c -o foo.o foo.c
ld -o xw startweak.o foo.o libbar.a
ld -o yw startweak.o libbar.a
ls -l x xw yw
-rwxrwxr-x 1 hjl hjl 4197928 May 5 12:59 x
-rwxrwxr-x 1 hjl hjl 2864 May 5 12:59 xw
-rwxrwxr-x 1 hjl hjl 1968 May 5 12:59 yw
address@hidden fini]$
--
You are receiving this mail because:
You are on the CC list for the bug.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug ld/18379] New: .fini_array support brings in unused codes,
hjl.tools at gmail dot com <=