From 177957dac462b6134c5134e6567019f73a401b8b Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Thu, 12 Oct 2017 00:19:29 +0300 Subject: [PATCH] Linker scripts: made it possible to override PROCESS_VM_BASE 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. --- libraries/chaos.ld | 5 ++++- servers/file_system/fat/Rakefile | 1 + servers/network/ipv4/Rakefile | 2 +- servers/servers.rake | 6 ++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/chaos.ld b/libraries/chaos.ld index 889feea5..4c936bc3 100644 --- a/libraries/chaos.ld +++ b/libraries/chaos.ld @@ -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) } diff --git a/servers/file_system/fat/Rakefile b/servers/file_system/fat/Rakefile index 56e5a41a..59bd0cc2 100644 --- a/servers/file_system/fat/Rakefile +++ b/servers/file_system/fat/Rakefile @@ -22,5 +22,6 @@ LIBRARIES = %w( ).freeze OUTPUT = 'fat'.freeze +EXTRA_LDFLAGS_PRE = '-Wl,--defsym=PROCESS_VM_BASE=0x50000000' load '../../servers.rake' diff --git a/servers/network/ipv4/Rakefile b/servers/network/ipv4/Rakefile index 7a427a63..8c76c11e 100644 --- a/servers/network/ipv4/Rakefile +++ b/servers/network/ipv4/Rakefile @@ -11,7 +11,7 @@ OBJECTS = %w( udp.o ).freeze -EXTRA_LDFLAGS = '-lgcc'.freeze +EXTRA_LIBS = '-lgcc'.freeze LIBRARIES = %w( ipc ipv4 diff --git a/servers/servers.rake b/servers/servers.rake index 1227ecc8..25e2e2a0 100644 --- a/servers/servers.rake +++ b/servers/servers.rake @@ -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" }