public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* exporting linker script symbols in statically linked binaries
@ 2007-04-03 23:11 Prasad Boddupalli
  2007-04-04  9:31 ` Dave Korn
  2007-04-10 21:22 ` Nick Clifton
  0 siblings, 2 replies; 3+ messages in thread
From: Prasad Boddupalli @ 2007-04-03 23:11 UTC (permalink / raw)
  To: binutils

Hello,

In statically linked binaries, certain parts of the data segment are
identified through symbolic names. For example, if the user requires
data pertaining to FAT file system, the linker script looks as
follows:

.rodata : {
    ...
    . = ALIGN(8);
    __start_fatfs = ABSOLUTE(.);
    *(.fatfs.data);
    __end_fatfs = ABSOLUTE(.);
    ...
}

The program accesses the start of fatfs data by referring to the
address of the symbol '_start_fatfs'. I cannot just declare

'extern char __start_fatfs[]'

in the executable as there could be different data, marked by
different symbols, all of which are not known to the program.

I could not create another section (starting at an agreed-upon name)
that contains <symbol name, address of required data> pairs as the
data to be packed (in the above read only section) exits as sections
in different files. For example, there exists one file 'fatfs.dat'
that contains just the above section '.fatfs.data'.

To date, the binaries were dynamically linked and the program could
access the values of linker script symbols by reading the dynamic
symbol table (that starts at _DYNAMIC symbol). However, the binaries
are now statically linked and .dynsym is not generated.

The binaries are not loaded by another program and hence the
alternative of reading the symbol table from the binary file and
exporting those linker script symbol values is ruled out.

Is there any way of exporting linker script symbols such that they can
be accessed without knowing them apriori ?

regards,
Prasad.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: exporting linker script symbols in statically linked binaries
  2007-04-03 23:11 exporting linker script symbols in statically linked binaries Prasad Boddupalli
@ 2007-04-04  9:31 ` Dave Korn
  2007-04-10 21:22 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Korn @ 2007-04-04  9:31 UTC (permalink / raw)
  To: 'Prasad Boddupalli', 'binutils'

On 04 April 2007 00:12, Prasad Boddupalli wrote:

> Is there any way of exporting linker script symbols such that they can
> be accessed without knowing them apriori ?


  Parse the -Map file?  :)

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: exporting linker script symbols in statically linked binaries
  2007-04-03 23:11 exporting linker script symbols in statically linked binaries Prasad Boddupalli
  2007-04-04  9:31 ` Dave Korn
@ 2007-04-10 21:22 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Clifton @ 2007-04-10 21:22 UTC (permalink / raw)
  To: Prasad Boddupalli; +Cc: binutils

Hi Prasad,

> Is there any way of exporting linker script symbols such that they can
> be accessed without knowing them apriori ?

I am not really clear as to why your code cannot know the names of 
symbols at compile time, but the short answer to your question is "no".

There are tricks that you can try.  You could put a magic number into 
the data section (eg 0x12345678) followed by linker directives to store 
the names of the symbols, and then have your code scan through the data 
section looking for this magic number and the names that follow it.

You could get the name of the executable via the argv[0] element and 
scan the file system for the corresponding file and then parse that.

You could do what David has suggested and write a script to parse the 
output of the linker's -Map option and dump the symbol names/addresses 
into a file which is then read by your program.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-04-10 21:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-03 23:11 exporting linker script symbols in statically linked binaries Prasad Boddupalli
2007-04-04  9:31 ` Dave Korn
2007-04-10 21:22 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).