Skip to content

Commit

Permalink
Linker scripts: made it possible to override PROCESS_VM_BASE
Browse files Browse the repository at this point in the history
This turned out to be crucial to be able to debug the issues I was having tonight, so I put the time into fixing this. It turned out to be quite trivial in the end, since a Stack Overflow user had done the vast majority of the work for us. Thanks Aravind!

Closes #104.
  • Loading branch information
perlun committed Oct 11, 2017
1 parent 0906af6 commit 177957d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion libraries/chaos.ld
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ OUTPUT_ARCH(i386)
ENTRY(startup)
SEARCH_DIR(/mnt/chaos/programming/libraries/static);

DEFAULT_PROCESS_VM_BASE = 0x40000000;
PROCESS_VM_BASE = DEFINED(PROCESS_VM_BASE) ? PROCESS_VM_BASE : DEFAULT_PROCESS_VM_BASE;

SECTIONS
{
/* Read-only sections, merged into text segment: */
. = 0x40000000 + SIZEOF_HEADERS;
. = PROCESS_VM_BASE + SIZEOF_HEADERS;
.interp : { *(.interp) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
Expand Down
1 change: 1 addition & 0 deletions servers/file_system/fat/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ LIBRARIES = %w(
).freeze

OUTPUT = 'fat'.freeze
EXTRA_LDFLAGS_PRE = '-Wl,--defsym=PROCESS_VM_BASE=0x50000000'

load '../../servers.rake'
2 changes: 1 addition & 1 deletion servers/network/ipv4/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OBJECTS = %w(
udp.o
).freeze

EXTRA_LDFLAGS = '-lgcc'.freeze
EXTRA_LIBS = '-lgcc'.freeze
LIBRARIES = %w(
ipc
ipv4
Expand Down
6 changes: 4 additions & 2 deletions servers/servers.rake
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ CFLAGS = (COMMON_CFLAGS + %w(
-Wstrict-prototypes
)).join(' ')

EXTRA_LDFLAGS ||= ''.freeze
EXTRA_LDFLAGS_PRE ||= ''.freeze
EXTRA_LIBS ||= ''.freeze
LDFLAGS = %W(
#{EXTRA_LDFLAGS_PRE}
#{LIBRARIES_DIR}/startup.o
-nostdlib
-Wl,-T,#{LIBRARIES_DIR}/chaos.ld
-m32
-L#{LIBRARIES_DIR}
#{EXTRA_LDFLAGS}
#{EXTRA_LIBS}
).freeze

LIBRARY_FILES = LIBRARIES.map { |l| "#{LIBRARIES_DIR}/lib#{l}.a" }
Expand Down

0 comments on commit 177957d

Please sign in to comment.