This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Stale entries left in GOT & PLT while discarding sections
- From: "Rajat Jain" <rajat dot noida dot india at gmail dot com>
- To: Fedora-tools-list at redhat dot com, binutils at sourceware dot org, rajat dot noida dot india at gmail dot com
- Date: Fri, 7 Apr 2006 19:09:55 +0530
- Subject: Stale entries left in GOT & PLT while discarding sections
Hi list,
I am trying to remove certain functions from a shared object at LINK time:
=========t.c==========
int i=2;
int j=3;
void fun() { i++; }
void gun() { j++; }
void sun() { fun(); }
====================
I created my shared object normally with " -shared -fPIC" and the
resultant shared object contains the following dynamic relocations:
$ objdump -R liba.so
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
000016a0 R_386_GLOB_DAT j
000016a4 R_386_GLOB_DAT i
000016c0 R_386_JUMP_SLOT fun
i.e., as expected, there are entries for "i" and "j" in the GOT and an
entry for "fun()" in the PLT. Now at link time, I am trying to
eliminate the symbols "i", "fun()" and "sun()" from the final shared
object. So this time I compiled my file with " -c -ffunction-sections
-fdata-sections " (to place each function / data in a separate
section) and whie linking, I changed the default linker script for the
shared object to /DISCARD/ the following sections:
.text.fun
.text.sun
.data.i
The result is as expected i.e. the symbols are totally removed from
the final shared object (definitions disappear, symbol entries
disappear etc). However, the GOT, the PLT (and associated relocations)
remain unchanged:
$ objdump -R liba.so
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
0000166c R_386_GLOB_DAT j
00001670 R_386_GLOB_DAT i
0000168c R_386_JUMP_SLOT fun
Due to this, when ever I try to link a program with this shared
object, the link goes fine but when I execute the program, the dynamic
linker gives me this error when trying to load the shared object:
symbol lookup error: ./liba.so: undefined symbol: i
AFAIK, this is because the dynamic linker tries to resolve the
R_386_GLOB_DAT relocation in the GOT before handing over the control
to the program:
1) As per my understanding the reason that the (stale) entries for the
removed sections / symbols are left in the GOT / PLT is because "ld"
creates the GOT and PLT at an early stage and later when reading the
linker script discards the sections as requested. It however does not
see (and does not care) that due to the removal of certain sections,
the entries in GOT and PLT have become inconsistent. Is my
understanding correct?
2) Is there any solution to the problem I am facing here? I mean is
there a way to remove the entries from the GOT and PLT as well?
Any pointers are welcome,
Thanks in Advance,
Rajat