1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00

Customizing linker file per architecture

This commit is contained in:
Andreas.Olofsson 2020-02-14 21:22:18 -05:00
parent 6b01f16935
commit 099b9527e3

View File

@ -25,19 +25,41 @@ ELF = sys.argv[3]
LINKERSCRIPT="tmp.ld" LINKERSCRIPT="tmp.ld"
if(ARCH=="riscv64"): if(ARCH=="rv32i"):
GCCROOT=ARCH + "-unknown-elf-" GCC="riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32"
GCCOPT=" -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles"
OUTPUT="riscv" OUTPUT="riscv"
else: else:
GCCROOT="e-" GCC="e-gcc"
GCCOPT=" -static -fvisibility=hidden -nostdlib -nostartfiles"
OUTPUT="epiphany" OUTPUT="epiphany"
############################################# #############################################
#PRINT LINKER FILE #PRINT LINKER FILE
f=open("tmp.ld",'w') f=open("tmp.ld",'w')
f.write("""OUTPUT_ARCH( "riscv" ) f.write("OUTPUT_ARCH( \"" + OUTPUT + "\" )\n")
ENTRY(_start) if(ARCH=="rv32i"):
f.write("""ENTRY(_start)
SECTIONS
{
. = 0x80000000;
.text.trap : { *(.text.trap) }
. = 0x00000000;
.text.init : { *(.text.init) }
. = ALIGN(0x1000);
.tohost : { *(.tohost) }
. = ALIGN(0x1000);
.text : { *(.text) }
. = ALIGN(0x1000);
.data : { *(.data) }
.data.string : { *(.data.string)}
.bss : { *(.bss) }
_end = .;
}""")
else:
f.write("""ENTRY(_start)
SECTIONS SECTIONS
{ {
. = 0x00000000; . = 0x00000000;
@ -51,12 +73,11 @@ SECTIONS
.bss : { *(.bss) } .bss : { *(.bss) }
_end = .; _end = .;
}""") }""")
f.close() f.close()
############################################# #############################################
#RUN GCC #RUN GCC
CMD=GCCROOT + "gcc -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles" + " -T" + LINKERSCRIPT + " -o " + ELF + " " + ASM CMD = GCC + GCCOPT + " -T" + LINKERSCRIPT + " -o " + ELF + " " + ASM
print(CMD) print(CMD)
os.system(CMD) os.system(CMD)
@ -64,5 +85,3 @@ os.system(CMD)