bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/12772] New: relocations from discarded sections stay


From: matz at suse dot de
Subject: [Bug ld/12772] New: relocations from discarded sections stay
Date: Tue, 17 May 2011 13:25:09 +0000

http://sourceware.org/bugzilla/show_bug.cgi?id=12772

           Summary: relocations from discarded sections stay
           Product: binutils
           Version: 2.22 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
        AssignedTo: address@hidden
        ReportedBy: address@hidden


(this got initially reported into Novell bugzilla #694266).
Compile this with the following compile command on x86_64-linux:

# g++ -O3 -Wl,-gc-sections -fpic -shared \
-fdata-sections -ffunction-sections \
-fvisibility-inlines-hidden -fvisibility=hidden \
-o test.so test.cpp

# cat test.cpp
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

extern "C" int __attribute__((visibility("default"))) func(char *ptr)
{
    static const char g_const[] = { 1, 1, 0 };
    memcpy(ptr, g_const, 3);

    return 0;
}

extern "C" char *func2(char *ptr)
{
    static char buf[4096];
    if (!getcwd(buf, sizeof(buf)))
        buf[0] = 0;
#define STR "test_string"
    memcpy(ptr, STR, sizeof(STR));
    return buf;
}

Note that func2 will be hidden, and as it's unreferenced the .text.func2
section will be discarded, as will be the .bss._ZZ5func2E3buf section:

# ...
./ld/ld-new: Removing unused section '.text.func2' in file
'show-link-discard-fail.o'
./ld/ld-new: Removing unused section '.bss._ZZ5func2E3buf' in file
'show-link-discard-fail.o'

But the relocation to getcwd (or better it's default decorated variant
getcwd@@GLIBC_2.2.5) will stay and transferred into the output file.
It should have been discarded too.  In fact the gc_sweep_hook on x86_64
for instance does lower the PLT count for this reloc, and hence seems
to assume that it really won't be emitted.  But alas, it is.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]