public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Todd_Manchester@nmss.com
To: binutils@sourceware.cygnus.com
Subject: symbol relocation
Date: Thu, 08 Jul 1999 14:11:00 -0000	[thread overview]
Message-ID: <852567A8.00743262.00@notes4.nmss.com> (raw)

I am trying to compile code for m68k, with the output format m68k-aout.
I can compile all the code, and link it to produce a relocatable object
file that is loaded by custom written loader (which utilizes the bfd
library).

However, the object file that is produced has what appear to be incorrect
refences to global variables, that is their location seems to be wrong.

For example, for the following code:
/* test.c */
char *str = "Test string 1";

void strdummy(char* s)
{
    s[0] = 't';
    return;
}

int main ()
{
    char *str2 = "test String 2";
    strdummy(str);
    strdummy(str2);
    str = "test string 3";
    str2 = str;
    return;
}

I compile with:
     gcc -save-temps -Wa,-L -m68000 -g -x c -c -o test.o test.c
     gcc -nostartfiles -Wl,--entry=.main,-r,-Map=test.map -o test.ro test.o
(This is a test case, the two step compilation is to mimic more complex
builds.)

I then do the following:
     objdump -x test.ro > test_ro.txt
     objdump -d --line-numbers test.ro > test_ro.s

Looking at the output, I see what appear to be some problems with sybol
addresses.
For instance:
In the original assembly the line is (test.s):
     movel _str,sp@-
In the disassembled output, the line is (test_ro.s):
     50: 2f39 0000 0094  movel 94 <___do_global_dtors+0x18>,%sp@-

I believe this to be wrong, because the the value of the symbol _str is not
 0x0000 0094, but is 0x00000110
This is shown in the line below from the symbol listing produced by objdump
 (test_ro.txt):
     00000110 g       .data 0000 00 07 _str

Why is the value in the code different from the symbol listing value (which
 I believe to be correct)?
All the relocation entries point to symbols such as .text, .data, and .bss;
   is there any way to find the
actual symbol that was being referenced?  (that way I could compute my own
relocations).
Am I not understanding the relocation process correctly?
I have look through the bfd source some; where can I go for more
information?

Some other information:
There is a relocation entry for this address (from test_ro.txt):
     00000052 32                .data+0xfffffef0

I am using the cygwin development environment, cygwin-b20.1
with gcc version egcs-2.91.57 19980901 (egcs-1.1 release), configured with
--target=m68k-aout.

I think this is causing programs that are loaded by my loader to address
incorrect locations in memory.
The loader is using the bfd library to perform final linking at load time
(to place the code at the correct address).
The loader sets up appropriate data structures and calls bfd_final_link()
to perform the final link.
It then extracts the section contents and loads them into memory.

Any suggestions as to what is happening with these symbols or this code
would be appreciated.
Also any hints as to how to proceed or problems with my approach would be
helpful.

I can provide more details if necessary.

-Todd Manchester


             reply	other threads:[~1999-07-08 14:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-08 14:11 Todd_Manchester [this message]
1999-07-09  9:52 ` Ian Lance Taylor
1999-07-09 14:14 Todd_Manchester
1999-07-09 22:06 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=852567A8.00743262.00@notes4.nmss.com \
    --to=todd_manchester@nmss.com \
    --cc=binutils@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).