end, edata, etext issues

Björn König bkoenig at alpha-tierchen.de
Mon Jun 25 09:11:23 UTC 2007


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




More information about the freebsd-hackers mailing list