Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:
Here's my transcript:Little of this seems to work, sorry. You guys keep saying, do this, do$ cat /tmp/m.c
that, no do it that way, go RTFM, but nobody has shown a complete
program that correctly shows the -size symbol to be giving anything
meaningful.
>
If I run this:
>
printf("%p\n", &_binary_hello_c_start);
printf("%p\n", &_binary_hello_c_end);
printf("%p\n", &_binary_hello_c_size);
>
I get:
>
00007ff6ef252010
00007ff6ef252056
00007ff5af240046
>
I can see that the first two can be subtracted to give the sizes of the
data, which is 70 or 0x46. 0x46 is the last byte of the address of
_size, so what's happening there? What's with the crap in bits 16-47?
>
I can extract the size using:
>
printf("%d\n", (unsigned short)&_binary_hello_c_size);
>
But something is not right. I've also asked what is the point of the
-size symbol if you can just do -end - -start, but nobody has explained.
#include <stdio.h>
#include <stdint.h>
extern uint64_t _binary_main_cpp_size;
extern uint8_t *_binary_main_cpp_start;
extern uint8_t *_binary_main_cpp_end;
int main()
{
printf("%p\n", &_binary_main_cpp_size);
printf("%p\n", &_binary_main_cpp_start);
printf("%p\n", &_binary_main_cpp_end);
return 0;
}
$ objcopy -I binary -B i386 -O elf64-x86-64 main.cpp /tmp/test.o
$ cc -o /tmp/m /tmp/m.c /tmp/test.o
$ /tmp/m
0x30e2
0x601034
0x604116
$ nm /tmp/m | grep _binary_main
0000000000604116 D _binary_main_cpp_end
00000000000030e2 A _binary_main_cpp_size
0000000000601034 D _binary_main_cpp_start
$ wc -c main.cpp
12514 main.cpp
$ printf 0x%x\n 12514
0x30e2
The size symbol requires no space in the resulting
executable memory image, and it's more convenient than
having to do the math (at run time, since the compiler
can't know the actual values).
Les messages affichés proviennent d'usenet.