Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jun 2007 10:54:06 +0200 (CEST)
From:      =?iso-8859-1?Q?Bj=F6rn_K=F6nig?= <bkoenig@alpha-tierchen.de>
To:        hackers@freebsd.org
Subject:   end, edata, etext issues
Message-ID:  <1500.192.168.1.2.1182761646.squirrel@webmail.alpha-tierchen.de>

next in thread | raw e-mail | index | archive | help
Hello,

I'm playing with FreeBSD on ARM. I noticed that sbrk(2) doesn't work
properly on this architecture. I still don't understand the whole process
of the initialisation of end, edata and etext. There are some oddities
that confuse me even more. Let me make an example:

  1 #include <stdio.h>
  2 extern end;
  3 extern edata;
  4 int main() {
  5         printf("edata:   %08x\n", edata);
  6         printf("end:     %08x\n", end);
  7         printf("sbrk(0): %08x\n", sbrk(0));
  8         return (0);
  9 }

> cc test.c && ./a.out
edata:   00000000
end:     00000000
sbrk(0): ffffffff

This is obviously not correct and the reason why program that rely sbrk(2)
are broken. I added the following code:

  1         .data
  2         .globl  curbrk
  3 curbrk:
  4         .word   end

and compiled the whole thing again:

> cc test.c curbrk.S && ./a.out
edata:   00000000
end:     0001070c
sbrk(0): 00100000

and it seems to work.

Another strange thing is that if I don't access "edata", e.g. leave
printf("edata:   %08x\n", edata); away, then sbrk still works, but "end"
is zero. In case I don't access "edata" or "end" at all I'll get a bus
error.

Is there somebody who can tell me how end depends on the presence curbrk
and edata in this example?

Regards
Björn





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1500.192.168.1.2.1182761646.squirrel>