Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Mr. P
Post
by Mr. P » Sat Jan 29, 2005 1:01 pm
Hi!
I've got this code:
Code: Select all
int gtest;
int main() {
int test;
printf("%x, %x", >est, &test);
return 0;
}
Which displays 442* and FFFFFFFC, the first address is correct but the second isn't, so why do variables in functions get incorrect addresses?
This is my linker script:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(main)
OUTPUT("test")
SECTIONS {
.text 0x44200000: {
*(.text)
}
.data : {
*(.data)
}
.rodata : {
*(.rodata)
}
.bss : {
*(.bss)
}
}
And this is how I compile:
Code: Select all
CFLAGS = -Wall -nostdlib -nostartfiles -fno-builtin -fwritable-strings -Isrc/include
OBJS = src/main.o
all: $(OBJS)
%.o:%.c
$(CC) $(CFLAGS) -o $@ -c $<
all:
$(LD) $(OBJS) -T link.ld
I'm posting in this forum because I'm loading it into my OS as a module.
FlashBurn
Post
by FlashBurn » Sat Jan 29, 2005 1:07 pm
Because local variables are on the stack!
Mr. P
Post
by Mr. P » Sat Jan 29, 2005 2:19 pm
well, my esp isn't pointing at 0xFFFFFFFF...
Candy
Member
Posts: 3882 Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven
Post
by Candy » Sat Jan 29, 2005 3:11 pm
Mr. P wrote:
well, my esp isn't pointing at 0xFFFFFFFF...
What if your ESP was 0 or 4 before getting there? That would cause this...
if you didn't link it through btw, this is also a known offset for jumps in unlinked files.
Mr. P
Post
by Mr. P » Sat Jan 29, 2005 3:32 pm
If the stack would be incorrect, my context switcher would warn me.
I checked the ESP at the position of the variable, and it was 0x44200FFC (correct).
Mr. P
Post
by Mr. P » Sat Jan 29, 2005 9:18 pm
Candy wrote:
Mr. P wrote:
well, my esp isn't pointing at 0xFFFFFFFF...
What if your ESP was 0 or 4 before getting there? That would cause this...
if you didn't link it through btw, this is also a known offset for jumps in unlinked files.
Candy, you lead me to the answer. EBP was 0.