Skip to content

Instantly share code, notes, and snippets.

@sam-falvo
Created July 30, 2015 19:21
Show Gist options
  • Save sam-falvo/a3aba3db13b382224cfc to your computer and use it in GitHub Desktop.
Save sam-falvo/a3aba3db13b382224cfc to your computer and use it in GitHub Desktop.
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.

@sam-falvo
Copy link
Author

Sorry; k.ld should read hw.ld.

@palmer-dabbelt
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment