$ /opt/riscv/bin/riscv64-unknown-elf-gcc -O3 -c -o hw.o hw.c
$ /opt/riscv/bin/riscv64-unknown-elf-ld -b binary -T k.ld hw.o -o hw.bin --nostdlib
NOTE: The -b binary
flag is required or else the command seg-faults.
extern void printm(char *, ...); | |
void main(void) { | |
printm("Hello world!\n"); | |
printm("Your name is %s\n", "unassigned"); | |
} |
OUTPUT_FORMAT(binary) | |
SECTIONS | |
{ | |
. = 0x0000000000020000; | |
.data : | |
{ | |
*(.data); | |
*(.rodata); | |
*(.bss); | |
} | |
. = 0xFF00000000000000; | |
.text : | |
{ | |
*(.text); | |
} | |
} |
$ /opt/riscv/bin/riscv64-unknown-elf-gcc -O3 -c -o hw.o hw.c
$ /opt/riscv/bin/riscv64-unknown-elf-ld -b binary -T k.ld hw.o -o hw.bin --nostdlib
NOTE: The -b binary
flag is required or else the command seg-faults.
I'm not sure what the goal is here, but it looks like our toolchain matches upstream
palmer.dabbelt a2 falvo-binary-linker $ make
riscv64-unknown-linux-gnu-gcc -O3 -c -o hw-riscv.o hw.c
gcc -O3 -c -o hw-x86.o hw.c
riscv64-unknown-linux-gnu-ld -b binary -T hw.ld hw-riscv.o -o hw-riscv.bin --nostdlib
ld -b binary -T hw.ld hw-x86.o -o hw-x86.bin --nostdlib
palmer.dabbelt a2 falvo-binary-linker $ file *.bin
hw-riscv.bin: ELF 64-bit LSB relocatable, version 1 (SYSV), not stripped
hw-x86.bin: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
what were you expecting?
Sorry; k.ld should read hw.ld.