Compile:
Code: Select all
gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -mno-red-zone -o helloc.o helloc.c
ld -T app.ld -o helloc.app helloc.o
Code: Select all
void b_output(const char *str);
int main(void)
{
b_output("Hello world, from C!\n");
return 0;
}
void b_output(const char *str)
{
asm volatile ("call *0x00100010" : : "S"(str)); // Make sure source register (RSI) has the string address (str)
}
Code: Select all
OUTPUT_FORMAT("binary")
OUTPUT_ARCH("i386:x86-64")
ENTRY(main)
SECTIONS
{
. = 0x0000000000200000;
.text : {
*(.text)
. = ALIGN(16);
}
.data : {
*(.data)
*(.rodata)
. = ALIGN(16);
}
__bss_start = .;
.bss : {
bss = .; _bss = .; __bss = .;
*(.bss);
}
end = .; _end = .; __end = .;
}
Code: Select all
00000000 4883EC08 sub rsp,byte +0x8
00000004 BF88002000 mov edi,0x200088
00000009 E80A000000 call qword 0x18
0000000E B800000000 mov eax,0x0
00000013 4883C408 add rsp,byte +0x8
00000017 C3 ret
00000018 4883EC08 sub rsp,byte +0x8
0000001C 48893C24 mov [rsp],rdi
00000020 488B0424 mov rax,[rsp]
00000024 4889C6 mov rsi,rax
00000027 FF142510001000 call qword [0x100010]
0000002E 90 nop
0000002F 4883C408 add rsp,byte +0x8
00000033 C3 ret
00000034 662E0F1F84000000 nop word [cs:rax+rax+0x0]
-0000
0000003E 6690 xchg ax,ax
00000040 1400 adc al,0x0
00000042 0000 add [rax],al
00000044 0000 add [rax],al
00000046 0000 add [rax],al
00000048 017A52 add [rdx+0x52],edi
0000004B 0001 add [rcx],al
0000004D 7810 js 0x5f
0000004F 011B add [rbx],ebx
00000051 0C07 or al,0x7
00000053 089001000014 or [rax+0x14000001],dl
00000059 0000 add [rax],al
0000005B 001C00 add [rax+rax],bl
0000005E 0000 add [rax],al
00000060 A0FFFFFF18000000 mov al,[qword 0x18ffffff]
-00
00000069 44 rex.r
0000006A 0E db 0x0e
0000006B 10530E adc [rbx+0xe],dl
0000006E 0800 or [rax],al
00000070 1400 adc al,0x0
00000072 0000 add [rax],al
00000074 3400 xor al,0x0
00000076 0000 add [rax],al
00000078 A0FFFFFF1C000000 mov al,[qword 0x1cffffff]
-00
00000081 44 rex.r
00000082 0E db 0x0e
00000083 10570E adc [rdi+0xe],dl
00000086 0800 or [rax],al
00000088 48 rex.w
00000089 656C gs insb
0000008B 6C insb
0000008C 6F outsd
0000008D 20776F and [rdi+0x6f],dh
00000090 726C jc 0xfe
00000092 642C20 fs sub al,0x20
00000095 66726F o16 jc 0x107
00000098 6D insd
00000099 204321 and [rbx+0x21],al
0000009C 0A00 or al,[rax]
0000009E 0000 add [rax],al
Code: Select all
00000000 48 83 EC 08 BF 88 00 20 00 E8 0A 00 00 00 B8 00 H...... ........
00000010 00 00 00 48 83 C4 08 C3 48 83 EC 08 48 89 3C 24 ...H....H...H.<$
00000020 48 8B 04 24 48 89 C6 FF 14 25 10 00 10 00 90 48 H..$H....%.....H
00000030 83 C4 08 C3 66 2E 0F 1F 84 00 00 00 00 00 66 90 ....f.........f.
00000040 14 00 00 00 00 00 00 00 01 7A 52 00 01 78 10 01 .........zR..x..
00000050 1B 0C 07 08 90 01 00 00 14 00 00 00 1C 00 00 00 ................
00000060 A0 FF FF FF 18 00 00 00 00 44 0E 10 53 0E 08 00 .........D..S...
00000070 14 00 00 00 34 00 00 00 A0 FF FF FF 1C 00 00 00 ....4...........
00000080 00 44 0E 10 57 0E 08 00 48 65 6C 6C 6F 20 77 6F .D..W...Hello wo
00000090 72 6C 64 2C 20 66 72 6F 6D 20 43 21 0A 00 00 00 rld, from C!....
What is the "junk" in 0x34 - 0x87? Is there a problem with my linker script?
Thanks,
Ian