Portál AbcLinuxu, 30. října 2025 22:48
Řešení dotazu:
$ cat foo.c
int fnc()
{
return 4;
}
$ gcc -o libfoo.so -g -shared foo.c
$ cat version.txt
author=rastos
$ objcopy --add-section .NOTES=version.txt libfoo.so libfoo.so.1
A keď sa pozriem dovnútra:
$ readelf -n libfoo.so.1 $ $objdump -s -j .NOTES libfoo.so.1 libfoo.so.1: file format elf64-x86-64 Contents of section .NOTES: 0000 61757468 6f723d72 6173746f 730a author=rastos.Cez "readelf -n" to nezobrazí nič, ale cez objdump áno.
$ cat bar.c
#include <stdio.h>
#include <unistd.h>
const char foo[] __attribute__((section(".interp"))) = "/lib64/ld-linux-x86-64.so.2";
void lib_main(void)
{
printf("Build-Time: " __DATE__ " " __TIME__ "\n");
#ifdef BRANCH
printf("Branch: " BRANCH "\n");
#endif
_exit(0);
}
$ gcc -fPIC -shared -o libBar.so -e lib_main -DBRANCH=\"experimental\" bar.c
$ ./libBar.so
Build-Time: May 9 2021 10:38:19
Branch: experimental
Poznámky:
bash: ./libBar.so: Accessing a corrupted shared library
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.