Liste des Groupes | Revenir à cl c |
On 01/06/2024 02:25, Scott Lurndal wrote:
>bart <bc@freeuk.com> writes:>
>Little of this seems to work, sorry. You guys keep saying, do this, do>
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: [attempt to reproduce example]
$ cat /tmp/m.c
#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).
Here's my transcript:
>
-------------------------------------
C:\c>copy hello.c main.cpp # create main.cpp, here it's 70 bytes
1 file(s) copied.
>
C:\c>type m.c # exact same code as yours
#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;
}
>
C:\c>objcopy -I binary -O elf64-x86-64 main.cpp test.o # make test.o
>
C:\c>gcc m.c test.o -o m.exe # build m executable
>
C:\c>m # run m.exe
00007ff5d5480046 # and the size is ...
00007ff715492010
00007ff715492056
[similar results under WSL]
Les messages affichés proviennent d'usenet.