david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[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:
Michael Brown 2008-10-09 22:22:01 +01:00
parent 3029eb0e84
commit 13d09e6719
11 changed files with 153 additions and 236 deletions

View File

@ -18,8 +18,8 @@ extern char _max_align[];
#define max_align ( ( unsigned int ) _max_align )
/* Linker symbols */
extern char _text[];
extern char _end[];
extern char _textdata[];
extern char _etextdata[];
/* within 1MB of 4GB is too close.
* MAX_ADDR is the maximum address we can easily do DMA to.
@ -47,8 +47,8 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
/* Get memory map and current location */
get_memmap ( &memmap );
start = virt_to_phys ( _text );
end = virt_to_phys ( _end );
start = virt_to_phys ( _textdata );
end = virt_to_phys ( _etextdata );
size = ( end - start );
padded_size = ( size + max_align - 1 );

View File

@ -66,7 +66,7 @@
.align 16
.globl hidemem_base
.globl hidemem_umalloc
.globl hidemem_text
.globl hidemem_textdata
memory_windows:
base_memory_window: .long 0x00000000, 0x00000000 /* Start of memory */
@ -76,7 +76,7 @@ ext_memory_window: .long 0x000a0000, 0x00000000 /* 640kB mark */
hidemem_umalloc: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */
hidemem_text: .long 0xffffffff, 0xffffffff /* Changes at runtime */
hidemem_textdata: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* End of memory */

View File

@ -55,8 +55,8 @@ extern struct hidden_region __data16 ( hidemem_umalloc );
#define hidemem_umalloc __use_data16 ( hidemem_umalloc )
/** Hidden text memory */
extern struct hidden_region __data16 ( hidemem_text );
#define hidemem_text __use_data16 ( hidemem_text )
extern struct hidden_region __data16 ( hidemem_textdata );
#define hidemem_textdata __use_data16 ( hidemem_textdata )
/** Assembly routine in e820mangler.S */
extern void int15();
@ -66,12 +66,12 @@ extern struct segoff __text16 ( int15_vector );
#define int15_vector __use_text16 ( int15_vector )
/* The linker defines these symbols for us */
extern char _text[];
extern char _end[];
extern char _text16_size[];
#define _text16_size ( ( unsigned int ) _text16_size )
extern char _data16_size[];
#define _data16_size ( ( unsigned int ) _data16_size )
extern char _textdata[];
extern char _etextdata[];
extern char _text16_memsz[];
#define _text16_memsz ( ( unsigned int ) _text16_memsz )
extern char _data16_memsz[];
#define _data16_memsz ( ( unsigned int ) _data16_memsz )
/**
* Hide region of memory from system memory map
@ -110,7 +110,7 @@ void hide_basemem ( void ) {
*
*/
void hide_umalloc ( physaddr_t start, physaddr_t end ) {
assert ( end <= virt_to_phys ( _text ) );
assert ( end <= virt_to_phys ( _textdata ) );
hide_region ( &hidemem_umalloc, start, end );
}
@ -118,9 +118,9 @@ void hide_umalloc ( physaddr_t start, physaddr_t end ) {
* Hide .text and .data
*
*/
void hide_text ( void ) {
hide_region ( &hidemem_text, virt_to_phys ( _text ),
virt_to_phys ( _end ) );
void hide_textdata ( void ) {
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
virt_to_phys ( _etextdata ) );
}
/**
@ -148,8 +148,8 @@ static void hide_etherboot ( void ) {
/* Initialise the hidden regions */
hide_basemem();
hide_umalloc ( virt_to_phys ( _text ), virt_to_phys ( _text ) );
hide_text();
hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) );
hide_textdata();
/* Some really moronic BIOSes bring up the PXE stack via the
* UNDI loader entry point and then don't bother to unload it
@ -161,8 +161,8 @@ static void hide_etherboot ( void ) {
* We use a heuristic to guess whether or not we are being
* loaded sensibly.
*/
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_size + 1024 - 1 ) >> 10 );
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_size + 1024 - 1 ) >> 10 );
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_memsz + 1024 - 1 ) >> 10 );
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_memsz + 1024 - 1 ) >> 10 );
fbms = get_fbms();
if ( ( rm_cs_top < fbms ) && ( rm_ds_top < fbms ) ) {
DBG ( "Detected potentially unsafe UNDI load at CS=%04x "

View File

@ -44,10 +44,10 @@ ppxe:
.byte SegDescCnt /* SegDescCnt */
.word 0 /* FirstSelector */
pxe_segments:
.word 0, 0, 0, _data16_size /* Stack */
.word 0, 0, 0, _data16_size /* UNDIData */
.word 0, 0, 0, _text16_size /* UNDICode */
.word 0, 0, 0, _text16_size /* UNDICodeWrite */
.word 0, 0, 0, _data16_memsz /* Stack */
.word 0, 0, 0, _data16_memsz /* UNDIData */
.word 0, 0, 0, _text16_memsz /* UNDICode */
.word 0, 0, 0, _text16_memsz /* UNDICodeWrite */
.word 0, 0, 0, 0 /* BC_Data */
.word 0, 0, 0, 0 /* BC_Code */
.word 0, 0, 0, 0 /* BC_CodeWrite */
@ -76,15 +76,15 @@ pxenv:
.long 0 /* PMEntry */
.word 0 /* PMSelector */
.word 0 /* StackSeg */
.word _data16_size /* StackSize */
.word _data16_memsz /* StackSize */
.word 0 /* BC_CodeSeg */
.word 0 /* BC_CodeSize */
.word 0 /* BC_DataSeg */
.word 0 /* BC_DataSize */
.word 0 /* UNDIDataSeg */
.word _data16_size /* UNDIDataSize */
.word _data16_memsz /* UNDIDataSize */
.word 0 /* UNDICodeSeg */
.word _text16_size /* UNDICodeSize */
.word _text16_memsz /* UNDICodeSize */
.word ppxe, 0 /* PXEPtr */
.equ pxenv_length, . - pxenv
.size pxenv, . - pxenv

View File

@ -144,7 +144,7 @@ got_sectors:
/* Jump to loaded copy */
ljmp $SYSSEG, $start_runtime
endseg: .word SYSSEG + _load_size_pgh
endseg: .word SYSSEG + _filesz_pgh
.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBW"
.long endseg

View File

@ -63,7 +63,7 @@ max_sector:
max_head:
.byte 0
load_length:
.long _load_size_sect
.long _filesz_sect
.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBL"

View File

@ -511,11 +511,11 @@ alloc_basemem:
shlw $6, %ax
/* .data16 segment address */
subw $_data16_size_pgh, %ax
subw $_data16_memsz_pgh, %ax
pushw %ax
/* .text16 segment address */
subw $_text16_size_pgh, %ax
subw $_text16_memsz_pgh, %ax
pushw %ax
/* Update FBMS */
@ -594,19 +594,19 @@ install_prealloc:
jnz 1f
movw %cs, %si
shll $4, %esi
1: addl $_payload_offset, %esi
1: addl $_payload_lma, %esi
/* Install .text16 and .data16 */
pushl %edi
movzwl %ax, %edi
shll $4, %edi
movl $_text16_size, %ecx
movl $_text16_memsz, %ecx
movl %ecx, %edx
call install_block /* .text16 */
movzwl %bx, %edi
shll $4, %edi
movl $_data16_progbits_size, %ecx
movl $_data16_size, %edx
movl $_data16_filesz, %ecx
movl $_data16_memsz, %edx
call install_block /* .data16 */
popl %edi
@ -622,8 +622,8 @@ install_prealloc:
* prior to reading the E820 memory map and relocating
* properly.
*/
movl $_textdata_progbits_size, %ecx
movl $_textdata_size, %edx
movl $_textdata_filesz, %ecx
movl $_textdata_memsz, %edx
call install_block
/* Initialise librm at current location */
@ -681,25 +681,25 @@ prot_call_vector:
#if COMPRESS
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _prefix_progbits_size
.long _prefix_lma
.long _prefix_filesz
.long _max_align
.ascii "PACK"
.long _text16_load_offset
.long _text16_progbits_size
.long _text16_lma
.long _text16_filesz
.long _max_align
.ascii "PACK"
.long _data16_load_offset
.long _data16_progbits_size
.long _data16_lma
.long _data16_filesz
.long _max_align
.ascii "PACK"
.long _textdata_load_offset
.long _textdata_progbits_size
.long _textdata_lma
.long _textdata_filesz
.long _max_align
#else /* COMPRESS */
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _load_size
.long _prefix_lma
.long _filesz
.long _max_align
#endif /* COMPRESS */

View File

@ -92,7 +92,7 @@ setup_sects:
root_flags:
.word 0
syssize:
.long _load_size_pgh - PREFIXPGH
.long _filesz_pgh - PREFIXPGH
.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBL"

View File

@ -32,8 +32,8 @@ segment_header:
.byte 0
.byte 0x04 /* Last segment */
.long 0x00007e00
imglen: .long _load_size - 512
memlen: .long _load_size - 512
imglen: .long _filesz - 512
memlen: .long _filesz - 512
.size segment_header, . - segment_header
.section ".zinfo.fixup", "a" /* Compressor fixup information */

View File

@ -30,7 +30,7 @@
.org 0x00
romheader:
.word 0xAA55 /* BIOS extension signature */
romheader_size: .byte _load_size_sect /* Size in 512-byte blocks */
romheader_size: .byte _filesz_sect /* Size in 512-byte blocks */
jmp init /* Initialisation vector */
checksum:
.byte 0
@ -58,12 +58,12 @@ pciheader:
.byte 0x03 /* PCI data structure revision */
.byte 0x02, 0x00, 0x00 /* Class code */
pciheader_image_length:
.word _load_size_sect /* Image length */
.word _filesz_sect /* Image length */
.word 0x0001 /* Revision level */
.byte 0x00 /* Code type */
.byte 0x80 /* Last image indicator */
pciheader_runtime_length:
.word _load_size_sect /* Maximum run-time image length */
.word _filesz_sect /* Maximum run-time image length */
.word 0x0000 /* Configuration utility code header */
.word 0x0000 /* DMTF CLP entry point */
.equ pciheader_len, . - pciheader
@ -130,9 +130,9 @@ undiheader:
.byte 0 /* Structure revision */
.byte 0,1,2 /* PXE version: 2.1.0 */
.word undiloader /* Offset to loader routine */
.word _data16_size /* Stack segment size */
.word _data16_size /* Data segment size */
.word _text16_size /* Code segment size */
.word _data16_memsz /* Stack segment size */
.word _data16_memsz /* Data segment size */
.word _text16_memsz /* Code segment size */
.ascii "PCIR" /* Bus type */
.equ undiheader_len, . - undiheader
.size undiheader, . - undiheader
@ -294,7 +294,7 @@ pmm_scan:
/* Shrink ROM and update checksum */
xorw %bx, %bx
xorw %si, %si
movw $_prefix_size_sect, %cx
movw $_prefix_memsz_sect, %cx
movb %cl, romheader_size
shlw $9, %cx
1: lodsb

View File

@ -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 );
}