[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Selective linking in ld
From: |
tbr |
Subject: |
Selective linking in ld |
Date: |
Tue, 23 Apr 2002 15:09:33 +0200 |
I am having a problem with what happens to references to sections that are
removed via ld's --gc-sections capability.
The assembler source (for PowerPC) looks like this:
(See attached file: tbr.asm)
.section .debug_frame
.long 0xab # marker
.long func1 # not included
.long func2 # included
.long 0xcd # marker
.section .text_func1,"x"
bl func1 # should disappear
func1: nop
.globl func1
.section .text_func2,"x"
bl func2 # should remain
func2: nop
.globl func2
.text
_start: bl func2 # always included
.globl _start
The problem is that after link the .text_func1 section has been correctly
removed, but the reference from the (debug) section .debug_frame to 'func1' has
the value 0x00000004, corresponding to the offset of the label func1 in the
section. I would much have preferred the value 0x00000000, so it was easy to
determine inside the debug section that the value is void.
The assembly and link was made like this:
(See attached file: tbr.bat)
as -o tbr.obj tbr.asm
ld -M --gc-sections -o result -T default.x tbr.obj
where the default.x script is here: (See attached file: default.x)
/* This file defines the layout of code and data both in the image file and
RAM */
/* The layout defined here is for a NON prommed i.e. downloaded
application.
* The text (code) segments start at 64 kB.
* The writable data segments start at 2 MB. */
OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc")
OUTPUT_ARCH(powerpc)
ENTRY(_start)
PROVIDE (__stack = 0);
_MAIN_STACK_SIZE_ = 0x100000;
_HEAP_SIZE_ = 0x100000;
SECTIONS
{
/* Make sure that the text segment is the first segment in the file */
/* We will not relocate the text segment. If the application is prommed,
code is run from ROM */
/* The code start address (or actually entry point) at 0x00010000
* makes PSIM select PPCBug mode by default which is what the UCC is
configured for. */
. = 0x00010000; /* <<--- Your code starts here */
.text :
{
_CODE_START_ = .;
*(.text*)
} =0
/* Other code segments immediately follows text segment */
.init : { *(.init) } =0
.fini : { *(.fini) } =0
. = 0x00200000; /* <<--- Your data starts here */
/* Readonly data */
.rodata : { *(.rodata) }
.rodata1 : { *(.rodata1) }
. = ALIGN( 8 );
_DATA_START_LOADED_ = .;
.data :
{
_DATA_START_RELOCATED_ = . ;
*(.data);
CONSTRUCTORS;
}
_DATA_SIZE_ = SIZEOF( .data);
_GOT_START_LOADED_ = _DATA_START_LOADED_ + _DATA_SIZE_;
.got :
{
_GOT_START_RELOCATED_ = .;
*(.got);
}
_GOT_SIZE_ = SIZEOF( .got );
/* We want the small data sections together, so single-instruction
offsets
* can access them all, and initialized data all before uninitialized, so
* we can make the executable and image file as small as possible. */
_SDATA_START_LOADED_ = _GOT_START_LOADED_ + _GOT_SIZE_;
.sdata :
{
_SDATA_START_RELOCATED_ = .;
*(.sdata);
}
_SDATA_SIZE_ = SIZEOF( .sdata );
_SDATA2_START_LOADED_ = _SDATA_START_LOADED_ + _SDATA_SIZE_;
.sdata2 :
{
_SDATA2_START_RELOCATED_ = .;
*(.sdata2)
}
_SDATA2_SIZE_ = SIZEOF( .sdata2 );
.sbss :
{
_SBSS_START_ = .;
*(.sbss)
*(.scommon)
*(.dynsbss)
_SBSS_END_ = .;
}
_SBSS_SIZE_ = SIZEOF( .sbss);
.bss :
{
_BSS_START_ = .;
*(.dynbss)
*(.bss)
*(COMMON)
_BSS_END_ = .;
}
_BSS_SIZE_ = SIZEOF( .bss);
_DATA_END_ = _BSS_START_ + _BSS_SIZE_;
/* The rest of this file is for debug information, no need to edit anything
here */
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* These must appear regardless of . */
}
Note that all .text* section are directed to .text.
The resulting linked result file has a 0x00000004 value for 'func1' in
.debug_frame, and the correct one for 'func2'.
The 0x00000004 value should have been 0x00000000, if you want to be sure not to
have problems in a debugger.
Section 1: .text Read/Execute
At address: v00010000 in section .text: _CODE_START_
_start
.text
#00010000: v00010000 48000009 bl v00010008
(func2)
#00010004: v00010004 48000005 bl v00010008
(func2)
At address: v00010008 in section .text: func2
#00010008: v00010008 60000000 ori r0,r0,0
Section 8: .debug_frame (debug)
#0001000C: v00000000 ---------------- --------000000AB -------- ----....
#00010010: v00000004 0000000400010008 000000CD-------- ........ ....----
^^^^^^^^
If the section becomes large, it may be difficult to distinguish a void value
from a proper one.
I hope someone can help me with a fix to ld for this problem.
Thorkil B. Rasmussen
(address@hidden)
tbr.asm
Description: Binary data
tbr.bat
Description: Binary data
default.x
Description: Binary data
- Selective linking in ld,
tbr <=