C arrays

Programming, for all ages and all languages.
AbstractYouShudNow
Member
Member
Posts: 92
Joined: Tue Aug 14, 2012 8:51 am

Re: C arrays

Post by AbstractYouShudNow »

My gcc adds some functions during compilaion it seems...
Consider reading about GCC Stack Smashing Protector on the wiki, most particularly its section 1.3, that should explain your problem, and ell you how to solve it.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: C arrays

Post by teodori »

No problem is the linking process. In the first case the string is accessed using local offsets and in the .text zone. In the second case the string is accessed using physical addresses and in the .rodata zone. The problem is the linker script...

1:
const uint8_t test[] = "xyz";
vga_write(VGA_BLACK, VGA_LIGHT_CYAN, test, 3, 1);
2:
vga_write(VGA_BLACK, VGA_LIGHT_CYAN, "abc", 3, 1);
LD script

Code: Select all

OUTPUT(kernel.img)
OUTPUT_FORMAT(binary)
ENTRY(start)
SECTIONS{
	.text : { *(.text) }
	.rodata : { *(.rodata) }
	.data : { *(.data) }
	.bss : { *(.bss) }
	.eh_frame : { *(.eh_frame) }
}
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: C arrays

Post by Owen »

You want *(.text*) and co for a start (GCC will emit symbols in sections like .text.foo, .data.bar, .bss.baz).

You're also missing *(COMMON), for common symbols from the common pseudo-section (they should go into BSS)

Also, you're outputting to binary yet I don't see any address information anywhere.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: C arrays

Post by teodori »

Ok found out what caused the problem. It was during the linking process. I corrected my linker script, now it works.
Thank you.
Post Reply