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.
When I tried it on my Linux system, I get an error "relocation R_X86_64_PC32 against absolute symbol `_binary_main_cpp_size' in section `.text' is disallowed". This is, I think, the correct response - from C you do not have direct access to absolute linker symbols. There is no space allocated for it in the executable, and it only exists as a constant in the link stage. Without an allocated address, declaring it as "extern" makes no sense. It makes even less sense to try to look at the /address/ of the symbol and think that it holds useful information. It's not often I say this, but I think Scott has got things muddled here.>>
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.
$ 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
Les messages affichés proviennent d'usenet.