Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Stale entries left in GOT & PLT while discarding sections: msg#00000

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



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe