주어진 ELF 실행 파일을 컴파일하는 데 사용되는 GCC 버전을 검색하는 방법은 무엇입니까?
주어진 실행 파일을 컴파일하는 데 사용되는 GCC 버전을 검색하고 싶습니다. 시도 readelf했지만 정보를 얻지 못했습니다. 이견있는 사람?
일반적으로 댓글 섹션에 저장됩니다.
strings -a <binary/library> |grep "GCC: ("
GCC 반환 : (GNU) XXX
strip -R .comment <binary>
strings -a <binary/library> |grep "GCC: ("
출력을 반환하지 않음
.comment (및 .note) 섹션을 제거하여 크기를 줄이는 것은 드문 일이 아닙니다.
strip --strip-all -R .note -R .comment <binary>
strip --strip-unneeded -R .note -R .comment <library>
참고 : busybox 문자열은 기본적으로 .comment 섹션에 필요한 -a 옵션을 지정합니다.
편집 : Berendra Tusla의 답변과는 달리이 방법이 작동하기 위해 디버깅 플래그로 컴파일 할 필요가 없습니다.
바이너리 예 :
# echo "int main(void){}">a.c
# gcc -o a a.c -s
# strings -a a |grep GCC
GCC: (GNU) 4.3.4
# strip -R .comment a
# strings -a a |grep GCC
#
개체 예 :
# gcc -c a.c -s
# strings -a a.o |grep GCC
GCC: (GNU) 4.3.4
# strip -R .comment a.o
# strings -a a |grep GCC
#
-g (디버깅) 플래그가없고 불필요한 기호를 제거하는 -s 플래그가 있음에 유의하십시오. .comment 섹션을 제거하지 않는 한 GCC 정보는 계속 사용할 수 있습니다. 이 정보를 그대로 유지해야하는 경우 makefile (또는 해당 빌드 스크립트)을 확인하여 -fno-ident가 $ CFLAGS에없고 $ STRIP 명령에 -R .comment가 없는지 확인해야 할 수 있습니다. -fno-ident는 gcc가 주석 섹션에서 이러한 기호를 생성하지 못하도록합니다.
다른 사람들의 말을 완료하려면 디버깅 정보로 컴파일하지 않는 한 객체 (또는 exe) 파일에 저장되지 않습니다 ! (옵션 -g). 디버그 정보로 컴파일하면 다음을 사용하여 다시 가져올 수 있습니다 readelf.
$ cat a.c
int main(void){ return 0; }
$ gcc a.c
$ readelf -wi a.out
$ gcc a.c -g
$ readelf -wi a.out
Contents of the .debug_info section:
Compilation Unit @ offset 0x0:
Length: 0x42 (32-bit)
Version: 2
Abbrev Offset: 0
Pointer Size: 4
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
< c> DW_AT_producer : (indirect string, offset: 0x0): GNU C 4.4.3 20100108 (prerelease)
<10> DW_AT_language : 1 (ANSI C)
<11> DW_AT_name : a.c
<15> DW_AT_comp_dir : (indirect string, offset: 0x22): /tmp
<19> DW_AT_low_pc : 0x8048394
<1d> DW_AT_high_pc : 0x804839e
<21> DW_AT_stmt_list : 0x0
<1><25>: Abbrev Number: 2 (DW_TAG_subprogram)
<26> DW_AT_external : 1
<27> DW_AT_name : (indirect string, offset: 0x27): main
<2b> DW_AT_decl_file : 1
<2c> DW_AT_decl_line : 1
<2d> DW_AT_prototyped : 1
<2e> DW_AT_type : <0x3e>
<32> DW_AT_low_pc : 0x8048394
<36> DW_AT_high_pc : 0x804839e
<3a> DW_AT_frame_base : 0x0 (location list)
<1><3e>: Abbrev Number: 3 (DW_TAG_base_type)
<3f> DW_AT_byte_size : 4
<40> DW_AT_encoding : 5 (signed)
<41> DW_AT_name : int
그것이 어떻게 말하는지보십시오 GNU C 4.4.3 20100108 (prerelease).
Yet another two ways (maybe a bit simpler) that I've just read about here: https://unix.stackexchange.com/questions/719/can-we-get-compiler-information-from-an-elf-binary
$ readelf -p .comment /usr/lib64/flash-plugin/libflashplayer.so
String dump of section '.comment':
[ 1] GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)
[ 2e] GCC: (GNU) 4.3.2
...
and
$ objdump -s --section .comment /usr/lib64/flash-plugin/libflashplayer.so
/usr/lib64/flash-plugin/libflashplayer.so: file format elf64-x86-64
Contents of section .comment:
0000 00474343 3a202847 4e552920 342e332e .GCC: (GNU) 4.3.
0010 32203230 30383131 30352028 52656420 2 20081105 (Red
0020 48617420 342e332e 322d3729 00004743 Hat 4.3.2-7)..GC
0030 433a2028 474e5529 20342e33 2e320000 C: (GNU) 4.3.2..
...
This information is not stored in the compiled object (c).
Actually, for C code you're totally out of luck. However, for C++ code you may find some information from symbol versions. Some functions from C++ runtime libraries are version-specific, and are marked as such in object files. Try this:
readelf -Wa file.exe | grep 'GCC[[:alnum:]_.]*' --only-match | sort | uniq | tail -n 1
It won't show you the version of GCC used, however. What it shows is the version of symbols in runtime supplied to the compiler. Usually the runtime is that of a compiler shipment, and its version is not less than the one shown with the above command.
You can use the elfinfo utility. This also supports detecting the compiler versions of Go and FPC, in addition to GCC.
'program story' 카테고리의 다른 글
| R은 변수 열 인덱스를 ggplot2에 전달합니다. (0) | 2020.11.15 |
|---|---|
| 전체 모델 세트를 formdata에 추가하고 MVC에서 가져 오는 방법 (0) | 2020.11.15 |
| Android : 사용자 정의보기의 높이와 너비를 얻는 방법은 무엇입니까? (0) | 2020.11.15 |
| Gerrit에 댓글을 추가 할 수 없습니다. (0) | 2020.11.15 |
| 접근성 및 이러한 모든 JavaScript 프레임 워크 (0) | 2020.11.15 |