mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 13:30:57 +03:00
[i386] Simplify linker script and standardise linker-defined symbol names
Reduce the number of sections within the linker script to match the number of practical sections within the output file. Define _section, _msection, _esection, _section_filesz, _section_memsz, and _section_lma for each section, replacing the mixture of symbols that previously existed. In particular, replace _text and _end with _textdata and _etextdata, to make it explicit within code that uses these symbols that the .text and .data sections are always treated as a single contiguous block.
This commit is contained in:
@@ -5,15 +5,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
OUTPUT_FORMAT ( "elf32-i386", "elf32-i386", "elf32-i386" )
|
||||
OUTPUT_ARCH ( i386 )
|
||||
ENTRY ( _entry )
|
||||
|
||||
SECTIONS {
|
||||
|
||||
/* All sections in the resulting file have consecutive load
|
||||
* addresses, but may have individual link addresses depending on
|
||||
* the memory model being used.
|
||||
/* Each section starts at a virtual address of zero.
|
||||
*
|
||||
* We guarantee alignment of virtual addresses to any alignment
|
||||
* specified by the constituent object files (e.g. via
|
||||
@@ -30,163 +24,123 @@ SECTIONS {
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Weak symbols that need zero values if not otherwise defined
|
||||
*/
|
||||
|
||||
. = 0;
|
||||
.weak : AT ( 0 ) {
|
||||
*(.weak)
|
||||
}
|
||||
_assert = ASSERT ( ( . == 0 ), ".weak is non-zero length" );
|
||||
|
||||
/*
|
||||
* The prefix
|
||||
*
|
||||
*/
|
||||
|
||||
_prefix_link_addr = 0;
|
||||
. = _prefix_link_addr;
|
||||
_prefix = .;
|
||||
|
||||
.prefix : AT ( _prefix_load_offset + __prefix ) {
|
||||
__prefix = .;
|
||||
_entry = .;
|
||||
.prefix 0x0 : AT ( _prefix_lma ) {
|
||||
_prefix = .;
|
||||
*(.prefix)
|
||||
*(.prefix.*)
|
||||
_eprefix_progbits = .;
|
||||
_mprefix = .;
|
||||
} .prefix_bss (NOLOAD) : {
|
||||
_eprefix = .;
|
||||
}
|
||||
|
||||
_eprefix = .;
|
||||
_prefix_filesz = ABSOLUTE ( _mprefix - _prefix );
|
||||
_prefix_memsz = ABSOLUTE ( _eprefix - _prefix );
|
||||
|
||||
/*
|
||||
* The 16-bit sections, if present
|
||||
* The 16-bit (real-mode) code section
|
||||
*
|
||||
*/
|
||||
|
||||
_text16_link_addr = 0;
|
||||
. = _text16_link_addr;
|
||||
_text16 = .;
|
||||
|
||||
/* We need to allow code at the NULL address in .text16 */
|
||||
|
||||
.text16 : AT ( _text16_load_offset + __text16 ) {
|
||||
__text16 = .;
|
||||
.text16 0x0 : AT ( _text16_lma ) {
|
||||
_text16 = .;
|
||||
*(.text16.null)
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
*(.text16)
|
||||
*(.text16.*)
|
||||
_etext16_progbits = .;
|
||||
} = 0x9090
|
||||
_mtext16 = .;
|
||||
} .text16_bss (NOLOAD) : {
|
||||
_etext16 = .;
|
||||
}
|
||||
_text16_filesz = ABSOLUTE ( _mtext16 - _text16 );
|
||||
_text16_memsz = ABSOLUTE ( _etext16 - _text16 );
|
||||
|
||||
_etext16 = .;
|
||||
/*
|
||||
* The 16-bit (real-mode) data section
|
||||
*
|
||||
*/
|
||||
|
||||
_data16_link_addr = 0;
|
||||
. = _data16_link_addr;
|
||||
_data16 = .;
|
||||
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
|
||||
.rodata16 : AT ( _data16_load_offset + __rodata16 ) {
|
||||
__rodata16 = .;
|
||||
.data16 0x0 : AT ( _data16_lma ) {
|
||||
_data16 = .;
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
*(.rodata16)
|
||||
*(.rodata16.*)
|
||||
}
|
||||
.data16 : AT ( _data16_load_offset + __data16 ) {
|
||||
__data16 = .;
|
||||
*(.data16)
|
||||
*(.data16.*)
|
||||
_edata16_progbits = .;
|
||||
}
|
||||
.bss16 : AT ( _data16_load_offset + __bss16 ) {
|
||||
__bss16 = .;
|
||||
_bss16 = .;
|
||||
_mdata16 = .;
|
||||
} .data16_bss (NOLOAD) : {
|
||||
*(.bss16)
|
||||
*(.bss16.*)
|
||||
_ebss16 = .;
|
||||
}
|
||||
.stack16 : AT ( _data16_load_offset + __stack16 ) {
|
||||
__stack16 = .;
|
||||
*(.stack16)
|
||||
*(.stack16.*)
|
||||
_edata16 = .;
|
||||
}
|
||||
|
||||
_edata16 = .;
|
||||
_data16_filesz = ABSOLUTE ( _mdata16 - _data16 );
|
||||
_data16_memsz = ABSOLUTE ( _edata16 - _data16 );
|
||||
|
||||
/*
|
||||
* The 32-bit sections
|
||||
*
|
||||
*/
|
||||
|
||||
_textdata_link_addr = 0;
|
||||
. = _textdata_link_addr;
|
||||
_textdata = .;
|
||||
|
||||
_text = .;
|
||||
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
|
||||
.text : AT ( _textdata_load_offset + __text ) {
|
||||
__text = .;
|
||||
.textdata 0x0 : AT ( _textdata_lma ) {
|
||||
_textdata = .;
|
||||
*(.text.null_trap)
|
||||
. += 1; /* Prevent NULL being valid */
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
} = 0x9090
|
||||
|
||||
_etext = .;
|
||||
|
||||
_data = .;
|
||||
|
||||
.rodata : AT ( _textdata_load_offset + __rodata ) {
|
||||
__rodata = .;
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
}
|
||||
.data : AT ( _textdata_load_offset + __data ) {
|
||||
__data = .;
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */
|
||||
_etextdata_progbits = .;
|
||||
}
|
||||
.bss : AT ( _textdata_load_offset + __bss ) {
|
||||
__bss = .;
|
||||
_bss = .;
|
||||
_mtextdata = .;
|
||||
} .textdata_bss (NOLOAD) : {
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
_ebss = .;
|
||||
}
|
||||
.stack : AT ( _textdata_load_offset + __stack ) {
|
||||
__stack = .;
|
||||
*(.stack)
|
||||
*(.stack.*)
|
||||
_etextdata = .;
|
||||
}
|
||||
|
||||
_edata = .;
|
||||
|
||||
_etextdata = .;
|
||||
|
||||
_end = .;
|
||||
_textdata_filesz = ABSOLUTE ( _mtextdata - _textdata );
|
||||
_textdata_memsz = ABSOLUTE ( _etextdata - _textdata );
|
||||
|
||||
/*
|
||||
* Compressor information block
|
||||
*
|
||||
*/
|
||||
|
||||
_zinfo_link_addr = 0;
|
||||
. = _zinfo_link_addr;
|
||||
_zinfo = .;
|
||||
|
||||
.zinfo : AT ( _zinfo_load_offset + __zinfo ) {
|
||||
__zinfo = .;
|
||||
_entry = .;
|
||||
.zinfo 0x0 : AT ( _zinfo_lma ) {
|
||||
_zinfo = .;
|
||||
*(.zinfo)
|
||||
*(.zinfo.*)
|
||||
_ezinfo_progbits = .;
|
||||
_mzinfo = .;
|
||||
} .zinfo_bss (NOLOAD) : {
|
||||
_ezinfo = .;
|
||||
}
|
||||
|
||||
_ezinfo = .;
|
||||
_zinfo_filesz = ABSOLUTE ( _mzinfo - _zinfo );
|
||||
_zinfo_memsz = ABSOLUTE ( _ezinfo - _zinfo );
|
||||
|
||||
/*
|
||||
* Weak symbols that need zero values if not otherwise defined
|
||||
*
|
||||
*/
|
||||
|
||||
.weak 0x0 : {
|
||||
_weak = .;
|
||||
*(.weak)
|
||||
_eweak = .;
|
||||
}
|
||||
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
|
||||
|
||||
/*
|
||||
* Dispose of the comment and note sections to make the link map
|
||||
* easier to read
|
||||
*
|
||||
*/
|
||||
|
||||
/DISCARD/ : {
|
||||
@@ -195,90 +149,53 @@ SECTIONS {
|
||||
}
|
||||
|
||||
/*
|
||||
* Load address calculations. The slightly obscure nature of the
|
||||
* calculations is because ALIGN(x) can only operate on the
|
||||
* location counter.
|
||||
* Load address calculations. In older versions of ld, ALIGN()
|
||||
* can operate only on the location counter, so we use that.
|
||||
*
|
||||
*/
|
||||
|
||||
_max_align = 16;
|
||||
_load_addr = 0;
|
||||
PROVIDE ( _max_align = 16 );
|
||||
. = 0;
|
||||
|
||||
. = _load_addr;
|
||||
_prefix_lma = .;
|
||||
. += _prefix_filesz;
|
||||
. = ALIGN ( _max_align );
|
||||
|
||||
. -= _prefix_link_addr;
|
||||
_prefix_load_offset = ALIGN ( _max_align );
|
||||
_prefix_load_addr = _prefix_link_addr + _prefix_load_offset;
|
||||
_prefix_size = _eprefix - _prefix;
|
||||
_prefix_progbits_size = _eprefix_progbits - _prefix;
|
||||
. = _prefix_load_addr + _prefix_progbits_size;
|
||||
_payload_lma = .;
|
||||
|
||||
. -= _text16_link_addr;
|
||||
_text16_load_offset = ALIGN ( _max_align );
|
||||
_text16_load_addr = _text16_link_addr + _text16_load_offset;
|
||||
_text16_size = _etext16 - _text16;
|
||||
_text16_progbits_size = _etext16_progbits - _text16;
|
||||
. = _text16_load_addr + _text16_progbits_size;
|
||||
_text16_lma = .;
|
||||
. += _text16_filesz;
|
||||
. = ALIGN ( _max_align );
|
||||
|
||||
. -= _data16_link_addr;
|
||||
_data16_load_offset = ALIGN ( _max_align );
|
||||
_data16_load_addr = _data16_link_addr + _data16_load_offset;
|
||||
_data16_size = _edata16 - _data16;
|
||||
_data16_progbits_size = _edata16_progbits - _data16;
|
||||
. = _data16_load_addr + _data16_progbits_size;
|
||||
_data16_lma = .;
|
||||
. += _data16_filesz;
|
||||
. = ALIGN ( _max_align );
|
||||
|
||||
. -= _textdata_link_addr;
|
||||
_textdata_load_offset = ALIGN ( _max_align );
|
||||
_textdata_load_addr = _textdata_link_addr + _textdata_load_offset;
|
||||
_textdata_size = _etextdata - _textdata;
|
||||
_textdata_progbits_size = _etextdata_progbits - _textdata;
|
||||
. = _textdata_load_addr + _textdata_progbits_size;
|
||||
_textdata_lma = .;
|
||||
. += _textdata_filesz;
|
||||
. = ALIGN ( _max_align );
|
||||
|
||||
_load_size = . - _load_addr;
|
||||
_filesz = .; /* Do not include zinfo block in file size */
|
||||
|
||||
. -= _zinfo_link_addr;
|
||||
_zinfo_load_offset = ALIGN ( _max_align );
|
||||
_zinfo_load_addr = _zinfo_link_addr + _zinfo_load_offset;
|
||||
_zinfo_size = _ezinfo - _zinfo;
|
||||
_zinfo_progbits_size = _ezinfo_progbits - _zinfo;
|
||||
. = _zinfo_load_addr + _zinfo_progbits_size;
|
||||
|
||||
_payload_offset = _text16_load_offset;
|
||||
|
||||
/*
|
||||
* Alignment checks. ALIGN() can only operate on the location
|
||||
* counter, so we set the location counter to each value we want
|
||||
* to check.
|
||||
*/
|
||||
|
||||
. = _prefix_load_addr - _prefix_link_addr;
|
||||
_assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
|
||||
"_prefix is badly aligned" );
|
||||
|
||||
. = _text16_load_addr - _text16_link_addr;
|
||||
_assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
|
||||
"_text16 is badly aligned" );
|
||||
|
||||
. = _data16_load_addr - _data16_link_addr;
|
||||
_assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
|
||||
"_data16 is badly aligned" );
|
||||
|
||||
. = _textdata_load_addr - _textdata_link_addr;
|
||||
_assert = ASSERT ( ( . == ALIGN ( _max_align ) ),
|
||||
"_text is badly aligned" );
|
||||
_zinfo_lma = .;
|
||||
. += _zinfo_filesz;
|
||||
. = ALIGN ( _max_align );
|
||||
|
||||
/*
|
||||
* Values calculated to save code from doing it
|
||||
*
|
||||
*/
|
||||
_prefix_size_pgh = ( ( _prefix_size + 15 ) / 16 );
|
||||
_prefix_size_sect = ( ( _prefix_size + 511 ) / 512 );
|
||||
_text16_size_pgh = ( ( _text16_size + 15 ) / 16 );
|
||||
_data16_size_pgh = ( ( _data16_size + 15 ) / 16 );
|
||||
_prefix_memsz_pgh = ( ( _prefix_memsz + 15 ) / 16 );
|
||||
_prefix_memsz_sect = ( ( _prefix_memsz + 511 ) / 512 );
|
||||
_text16_memsz_pgh = ( ( _text16_memsz + 15 ) / 16 );
|
||||
_data16_memsz_pgh = ( ( _data16_memsz + 15 ) / 16 );
|
||||
|
||||
/*
|
||||
* Load sizes in paragraphs and sectors. Note that wherever the
|
||||
* _load_size variables are used, there must be a corresponding
|
||||
* File size in paragraphs and sectors. Note that wherever the
|
||||
* _filesz variables are used, there must be a corresponding
|
||||
* .zinfo.fixup section.
|
||||
*
|
||||
*/
|
||||
_load_size_pgh = ( ( _load_size + 15 ) / 16 );
|
||||
_load_size_sect = ( ( _load_size + 511 ) / 512 );
|
||||
_filesz_pgh = ( ( _filesz + 15 ) / 16 );
|
||||
_filesz_sect = ( ( _filesz + 511 ) / 512 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user