custom linker script for user apps to guarantee that sections are page-aligned
This commit is contained in:
parent
225ea67c64
commit
7ec40a1d7e
2 changed files with 59 additions and 18 deletions
|
|
@ -52,7 +52,7 @@ echo " command = ld -r \$in -o \$out" >> build.ninja
|
||||||
|
|
||||||
#eventually maybe a libc will be linked in
|
#eventually maybe a libc will be linked in
|
||||||
echo "rule user_app_ld" >> build.ninja
|
echo "rule user_app_ld" >> build.ninja
|
||||||
echo " command = ld ${COMMON_LD_FLAGS} \$in -o \$out" >> build.ninja
|
echo " command = ld ${COMMON_LD_FLAGS} -T src/user-apps/link.ld \$in -o \$out" >> build.ninja
|
||||||
|
|
||||||
#builds everything in a directory
|
#builds everything in a directory
|
||||||
# $1 - source directory
|
# $1 - source directory
|
||||||
|
|
@ -102,6 +102,7 @@ cp_apps=""
|
||||||
app_deps=""
|
app_deps=""
|
||||||
|
|
||||||
for dir in src/user-apps/*; do
|
for dir in src/user-apps/*; do
|
||||||
|
if [ -d $dir ]; then
|
||||||
|
|
||||||
if [ -e $dir/libraries.txt ]; then
|
if [ -e $dir/libraries.txt ]; then
|
||||||
lib_paths=$(cat $dir/libraries.txt | sed -e 's/^.*$/build\/user-libs\/\0\/lib\0.o/' | tr '\n' ' ')
|
lib_paths=$(cat $dir/libraries.txt | sed -e 's/^.*$/build\/user-libs\/\0\/lib\0.o/' | tr '\n' ' ')
|
||||||
|
|
@ -121,6 +122,7 @@ for dir in src/user-apps/*; do
|
||||||
"cp $build_elf $disk_elf &&")
|
"cp $build_elf $disk_elf &&")
|
||||||
app_deps="$app_deps $build_elf"
|
app_deps="$app_deps $build_elf"
|
||||||
|
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "rule disk" >> build.ninja
|
echo "rule disk" >> build.ninja
|
||||||
|
|
|
||||||
39
src/user-apps/link.ld
Normal file
39
src/user-apps/link.ld
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
OUTPUT_FORMAT(elf64-x86-64)
|
||||||
|
OUTPUT_ARCH(i386:x86-64)
|
||||||
|
|
||||||
|
ENTRY(_start)
|
||||||
|
|
||||||
|
PHDRS {
|
||||||
|
rx PT_LOAD FLAGS(5);
|
||||||
|
ro PT_LOAD FLAGS(4);
|
||||||
|
rw PT_LOAD FLAGS(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
|
||||||
|
. = 0x400000;
|
||||||
|
|
||||||
|
.text : {
|
||||||
|
*(.text .text.*)
|
||||||
|
} : rx
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
|
||||||
|
.rodata : {
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
} : ro
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
|
||||||
|
.data : {
|
||||||
|
*(.data .data.*)
|
||||||
|
} : rw
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
|
||||||
|
.bss : {
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
|
} : rw
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue