Partial Linking with GNU binutils

"Ian Broster" <spam@broster.co.uk>
28 Jul 2005 02:39:51 -0400

          From comp.compilers

Related articles
Partial Linking with GNU binutils spam@broster.co.uk (Ian Broster) (2005-07-28)
| List of all articles for this month |

From: "Ian Broster" <spam@broster.co.uk>
Newsgroups: comp.compilers
Date: 28 Jul 2005 02:39:51 -0400
Organization: The University of York, UK
Keywords: linker, question
Posted-Date: 28 Jul 2005 02:39:50 EDT

Is there any reason why when partial linking with GNU ld -r that
local symbols cannot be completely resolved and therefore
removed from the symbol table?


It seems that a link with ld -r still requires the local
symbols to be kept; only on the final link to produce
a static executable are the local symbols finally
resolved. For example, follow the symbol p1 through
the process below.


Thanks for any insight!


Ian






% gcc -c -o a.o a.c
% nm a.o
00000044 T global
00000000 T main
0000002c T p1
                      U p2
                      U printf
% # p1 is global, but not needed beyond this [group of] file[s].
% # Make p1 local
% objcopy -L p1 a.o
% # Partial link (normally with more files...)
% ld -r -o a1.o a.o
% # Have a look at the symbol table; p1 is local.
% nm a1.o
00000044 T global
00000000 T main
0000002c t p1
                      U p2
                      U printf
% # But the code still requires the symbol, see address 0x20:


objdump -d a1.o


a1.o: file format elf32-i386


Disassembly of section .text:


00000000 <main>:
          0: 55 push %ebp
          1: 89 e5 mov %esp,%ebp
          3: 83 ec 08 sub $0x8,%esp
          6: 83 e4 f0 and $0xfffffff0,%esp
          9: b8 00 00 00 00 mov $0x0,%eax
          e: 29 c4 sub %eax,%esp
        10: 83 ec 0c sub $0xc,%esp
        13: 68 00 00 00 00 push $0x0
        18: e8 fc ff ff ff call 19 <main+0x19>
        1d: 83 c4 10 add $0x10,%esp
        20: e8 fc ff ff ff call 21 <main+0x21>
        25: e8 fc ff ff ff call 26 <main+0x26>
        2a: c9 leave
        2b: c3 ret


0000002c <p1>:
        2c: 55 push %ebp
        2d: 89 e5 mov %esp,%ebp
        2f: 83 ec 08 sub $0x8,%esp
        32: 83 ec 0c sub $0xc,%esp
        35: 68 06 00 00 00 push $0x6
        3a: e8 fc ff ff ff call 3b <p1+0xf>
        3f: 83 c4 10 add $0x10,%esp
        42: c9 leave
        43: c3 ret


00000044 <global>:
        44: 55 push %ebp
        45: 89 e5 mov %esp,%ebp
        47: 83 ec 08 sub $0x8,%esp
        4a: 83 ec 0c sub $0xc,%esp
        4d: 68 0a 00 00 00 push $0xa
        52: e8 fc ff ff ff call 53 <global+0xf>
        57: 83 c4 10 add $0x10,%esp
        5a: c9 leave
        5b: c3 ret


% Indeed, we cannot remove it.
% objcopy -N p1 a1.o big.o
BFD: big.o: symbol `p1' required but not present
objcopy: big.o: No symbols


--
Ian Broster


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.