Skip to content

Commit

Permalink
[build] Fix stack placement with insane versions of binutils
Browse files Browse the repository at this point in the history
Some versions of binutils will treat literal numbers within a section
description as being relative to the start of the section.  This
results in our stack being placed at .bss+0x40000 instead of at
the fixed address 0x40000.

Fix by declaring the Forbidden Region (0x30000-0x40000) using absolute
symbols defined outside of a section description.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
  • Loading branch information
mcb30 committed May 10, 2017
1 parent 398bdbd commit 072a64f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/script.lds
Expand Up @@ -65,20 +65,24 @@ SECTIONS {
_data_len = ABSOLUTE ( _edata ) - ABSOLUTE ( _data );
_payload_len = ABSOLUTE ( _epayload ) - ABSOLUTE ( _payload );

/* bootmgr.exe hardcodes the address 0x30000 for use as a
* buffer accessible by real-mode code. We can't fit our
* code, data, and stack below this region, so explicitly
* place the stack higher in memory.
*/
_forbidden_start = 0x30000;
_forbidden_end = 0x40000;

/* Uninitialised data section */
.bss ( NOLOAD ) : {
_bss = .;
*(.bss)
*(.bss.*)
*(COMMON)

/* bootmgr.exe hardcodes the address 0x30000 for use
* as a buffer accessible by real-mode code. We can't
* fit our code, data, and stack below this region, so
* explicitly place the stack higher in memory.
*/
ASSERT ( ABSOLUTE ( . ) <= 0x30000, "Binary too large" );
. = 0x40000;
ASSERT ( ABSOLUTE ( . ) <= ABSOLUTE ( _forbidden_start ),
"Binary is too large" );
. = ABSOLUTE ( _forbidden_end );

*(.stack)
*(.stack.*)
Expand Down

0 comments on commit 072a64f

Please sign in to comment.