导航:首页 > 源码编译 > 查看elf程序编译参数

查看elf程序编译参数

发布时间:2023-08-16 11:43:20

❶ 怎样查看自己电脑的编译器是多少位的

编译器有好多种,每个语言都有,一般都有-v或者--version命令可以看版本信息,包括生成的代码对应的机型(target),例如:Target: x86_64-w64-windows-gnu 就是生成64位的x86-64机器码,编译时可以靠-m32等命令控制.


至于编译器本身,那跟你下载时的版本有关,如果你确实需要了解类似GCC本身是多少位的,可以这样:

linux下:

filexxx#xxx代表程序名

例如:

[cosmia@excalibur~]$filesqlite3.i686sqlite3.x86_64
sqlite3.i686:ELF32-bitLSBexecutable,Intel80386,version1(SYSV),dynamicallylinked(usessharedlibs),forGNU/Linux2.6.32,BuildID[sha1]=,stripped
sqlite3.x86_64:ELF64-bitLSBexecutable,x86-64,version1(SYSV),dynamicallylinked(usessharedlibs),forGNU/Linux2.6.32,BuildID[sha1]=,stripped


windows下:

用7zip打开那个.exe文件,看cpu信息


详细参考方法:

http://www.hu.com/question/23027723

❷ 求从交叉编译器生成的elf文件中读取全局变量信息的函数

楼主,这个恐怕不是一个函数能解决的,ELF文件格式还是有点复杂的。 我以前做过类似的功能,从ELF文件中加载所有符号表信息,字符串信息,并下载代码。 我推荐你用一个开源的库:ELFIO。 我想这个库应该可以实现你的功能,只是你要去研究一下它的用法。 当然,你得首先对ELF文件格式有所了解。ELFIO库下载地址: http://sourceforge.net/projects/elfio/ ================================这是我以前写过的加载ELF中所有Section信息的例子: BOOL LoadELF(char* pFilename)
{
CString strName,tmp;
IELFI* pReader;

if ( ERR_ELFIO_NO_ERROR != ELFIO::GetInstance()->CreateELFI( &pReader ) ) {
Msg( "Can't create ELF reader.\r\n",2,0);
return FALSE;
}
if ( ERR_ELFIO_NO_ERROR != pReader->Load(pFilename ) ) {
Msg( "Can't open input elf file.\r\n",2,0);
return FALSE;
} int nSecNo = pReader->GetSectionsNum();
for (int i = 0; i < nSecNo; i++ )
{ // For all sections
const IELFISection* pSec = pReader->GetSection( i );
printf("%s\n",pSec->GetName().c_str());
Elf32_Half index= pSec->GetIndex() ;
std::string name = pSec->GetName() ;
Elf32_Word type =pSec->GetType() ;
Elf32_Addr addr = pSec->GetAddress() ;
Elf32_Word size = pSec->GetSize() ;
Elf32_Word link = pSec->GetLink() ;
Elf32_Word info = pSec->GetInfo() ;
Elf32_Word aa = pSec->GetAddrAlign() ;
Elf32_Word esize = pSec->GetEntrySize() ;
const char* p = pSec->GetData() ;
Elf32_Word flag = pSec->GetFlags() ;
strName = pSec->GetName().c_str();strName.MakeUpper();
//如果未指定section,读取所有SHF_EXECINSTR属性的Section
if(g_MapScetion.GetCount()==0)
{
if(flag&SHF_EXECINSTR)
LoadElfSection((BYTE*)pSec->GetData(),pSec->GetAddress(),pSec->GetSize(),pList,pAddInfo);
}
else
{
if(g_MapScetion.Lookup(strName,tmp))
LoadElfSection((BYTE*)pSec->GetData(),pSec->GetAddress(),pSec->GetSize(),pList,pAddInfo);
}

pSec->Release();
} pReader->Release();
return TRUE;
}

❸ 如何看linux编译后的文件

有,反编译为汇编,不过因为 Linux 大部分为开源软件,不如找源代码……
所以,我没注意过怎么反汇编。一般经常调试程序的人都会这个。

另外,好像 gcc 编译时可以生成过渡代码,现在也有看过度代码的,好像和汇编类似。

❹ 请问如何查看一个elf文件的编译参数

我尝试过使用readelf,没有从输出信息中发现我想要的

❺ 如何查看程序被哪个版本编译器编译的linux-gcc

那是不可能的,除非你加入了调试信息,也就是编译的时候加入了-g参数,然后用gdb调试就可以显示。最大程度上查看一个elf文件信息。



readelf -Wa a.out | head
readelf -wi a.out
readelf -p .comment a.out
objmp -s --section .comment audioplayer



如下:

[root@localhost rootfs]# readelf -Wa bin/gzip

复制代码
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0xa080
Start of program headers: 52 (bytes into file)
Start of section headers: 1975444 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 25
Section header string table index: 24

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .note.ABI-tag NOTE 000080f4 0000f4 000020 00 A 0 0 4
[ 2] .init PROGBITS 00008114 000114 00000c 00 AX 0 0 4
[ 3] .text PROGBITS 00008120 000120 17fcfc 00 AX 0 0 16
[ 4] __libc_freeres_fn PROGBITS 00187e1c 17fe1c 000f20 00 AX 0 0 4
[ 5] __libc_thread_fre PROGBITS 00188d3c 180d3c 0000e4 00 AX 0 0 4
[ 6] .fini PROGBITS 00188e20 180e20 000008 00 AX 0 0 4
[ 7] .rodata PROGBITS 00188e28 180e28 058147 00 A 0 0 8
[ 8] __libc_subfreeres PROGBITS 001e0f70 1d8f70 00005c 00 A 0 0 4
[ 9] __libc_atexit PROGBITS 001e0fcc 1d8fcc 000004 00 A 0 0 4
[10] __libc_thread_sub PROGBITS 001e0fd0 1d8fd0 000008 00 A 0 0 4
[11] .ARM.extab PROGBITS 001e0fd8 1d8fd8 001b04 00 A 0 0 4
[12] .ARM.exidx ARM_EXIDX 001e2adc 1daadc 006ea8 00 AL 3 0 4
[13] .tdata PROGBITS 001f1984 1e1984 000018 00 WAT 0 0 4
[14] .tbss NOBITS 001f199c 1e199c 000034 00 WAT 0 0 4
[15] .init_array INIT_ARRAY 001f199c 1e199c 000004 00 WA 0 0 4
[16] .fini_array FINI_ARRAY 001f19a0 1e19a0 000008 00 WA 0 0 4
[17] .jcr PROGBITS 001f19a8 1e19a8 000004 00 WA 0 0 4
[18] .data.rel.ro PROGBITS 001f19ac 1e19ac 00002c 00 WA 0 0 4
[19] .got PROGBITS 001f19d8 1e19d8 00007c 04 WA 0 0 4
[20] .data PROGBITS 001f1a58 1e1a58 0008f7 00 WA 0 0 8
[21] .bss NOBITS 001f2350 1e234f 004828 00 WA 0 0 8
[22] __libc_freeres_pt NOBITS 001f6b78 1e234f 00003c 00 WA 0 0 4
[23] .ARM.attributes ARM_ATTRIBUTES 00000000 1e234f 00002b 00 0 0 1
[24] .shstrtab STRTAB 00000000 1e237a 000118 00 0 0 1

Section to Segment mapping:
Segment Sections...
00 .ARM.exidx
01 .note.ABI-tag .init .text __libc_freeres_fn __libc_thread_freeres_fn .fini .rodata __libc_subfreeres __libc_atexit __libc_thread_subfreeres .ARM.extab .ARM.exidx
02 .tdata .init_array .fini_array .jcr .data.rel.ro .got .data .bss __libc_freeres_ptrs
03 .note.ABI-tag
04 .tdata .tbss

Attribute Section: aeabi
File Attributes
Tag_CPU_name: "5TE"
Tag_CPU_arch: v5TE
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-1
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align8_needed: Yes
Tag_ABI_align8_preserved: Yes, except leaf SP
Tag_ABI_enum_size: int
Tag_unknown_44: 1 (0x1)
复制代码

How to retrieve the GCC version used to compile a given ELF executable? http://stackoverflow.com/questions/2387040/how-to-retrieve-the-gcc-version-used-to-compile-a-given-elf-executable

QUES: I'd like to retrieve the GCC version used to compile a given executable. I tried readelf but didn't get the information. Any thoughts?

ANS: To complete what others have said: it's not stored in the object (or exe) file, unless you compile with debugging information! (option -g). If you compile with debug info, you can get it back with readelf:

复制代码
[root@localhost test]# gcc a.c
[root@localhost test]# readelf -wi a.out
[root@localhost test]# gcc a.c -g
[root@localhost test]# readelf -wi a.out
The section .debug_info contains:

Compilation Unit @ offset 0x0:
Length: 135
Version: 2
Abbrev Offset: 0
Pointer Size: 8
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
DW_AT_stmt_list : 0
DW_AT_high_pc : 0x400453
DW_AT_low_pc : 0x400448
DW_AT_procer : GNU C 4.1.2 20080704 (Red Hat 4.1.2-55)
DW_AT_language : 1 (ANSI C)
DW_AT_name : a.c
DW_AT_comp_dir : /work/farsight/test
<1><61>: Abbrev Number: 2 (DW_TAG_subprogram)
DW_AT_external : 1
DW_AT_name : main
DW_AT_decl_file : 1
DW_AT_decl_line : 4
DW_AT_prototyped : 1
DW_AT_type : <83>
DW_AT_low_pc : 0x400448
DW_AT_high_pc : 0x400453
DW_AT_frame_base : 0 (location list)
<1><83>: Abbrev Number: 3 (DW_TAG_base_type)
DW_AT_name : int
DW_AT_byte_size : 4
DW_AT_encoding : 5 (signed)
复制代码

ANS2:

❻ andriod系统里怎么使用readelf命令

readelf <option(s)> elf-file(s)

[功能]
用于显示elf格式文件的信息。

[描述]
readelf用来显示一个或者多个elf格式的目标文件的信息,可以通过它的选项来控制显示哪些信息。这里的elf-file(s)就表示那些被检查的文件。可以支持32位,64位的elf格式文件,也支持包含elf文件的文档(这里一般指的是使用ar命令将一些elf文件打包之后生成的例如lib*.a之类的“静态库”文件)。
这个程序和objmp提供的功能类似,但是它显示的信息更为具体,并且它不依赖BFD库(BFD库是一个GNU项目,它的目标就是希望通过一种统一的接口来处理不同的目标文件),所以即使BFD库有什么bug存在的话也不会影响到readelf程序。
运行readelf的时候,除了-v和-H之外,其它的选项必须有一个被指定。

ELF文件类型:
种类型的ELF文件:
a)可重定位文件:用户和其他目标文件一起创建可执行文件或者共享目标文件,例如lib*.a文件。
b)可执行文件:用于生成进程映像,载入内存执行,例如编译好的可执行文件a.out。
c)共享目标文件:用于和其他共享目标文件或者可重定位文件一起生成elf目标文件或者和执行文件一起创建进程映像,例如lib*.so文件。

ELF文件作用:
ELF文件参与程序的连接(建立一个程序)和程序的执行(运行一个程序),所以可以从不同的角度来看待elf格式的文件:
a)如果用于编译和链接(可重定位文件),则编译器和链接器将把elf文件看作是节头表描述的节的集合,程序头表可选。
b)如果用于加载执行(可执行文件),则加载器则将把elf文件看作是程序头表描述的段的集合,一个段可能包含多个节,节头表可选。
c)如果是共享文件,则两者都含有。

ELF文件总体组成:
elf文件头描述elf文件的总体信息。包括:
系统相关,类型相关,加载相关,链接相关。
系统相关表示:elf文件标识的魔术数,以及硬件和平台等相关信息,增加了elf文件的移植性,使交叉编译成为可能。
类型相关就是前面说的那个类型。
加载相关:包括程序头表相关信息。
链接相关:节头表相关信息。

项(分别以长格式和短格式给出了):
-a
--all 显示全部信息,等价于 -h -l -S -s -r -d -V -A -I.

-h
--file-header 显示elf文件开始的文件头信息.

-l
--program-headers
--segments 显示程序头(段头)信息(如果有的话)。

-S
--section-headers
--sections 显示节头信息(如果有的话)。

-g
--section-groups 显示节组信息(如果有的话)。

-t
--section-details 显示节的详细信息(-S的)。

-s
--syms
--symbols 显示符号表段中的项(如果有的话)。

-e
--headers 显示全部头信息,等价于: -h -l -S

-n
--notes 显示note段(内核注释)的信息。

-r
--relocs 显示可重定位段的信息。

-u
--unwind 显示unwind段信息。当前只支持IA64 ELF的unwind段信息。

-d
--dynamic 显示动态段的信息。

-V
--version-info 显示版本段的信息。

-A
--arch-specific 显示CPU构架信息。

-D
--use-dynamic 使用动态段中的符号表显示符号,而不是使用符号段。

-x <number or name>
--hex-mp=<number or name> 以16进制方式显示指定段内内容。number指定段表中段的索引,或字符串指定文件中的段名。

-w[liaprmfFsoR] or
--debug-mp[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges]
显示调试段中指定的内容。

-I
--histogram 显示符号的时候,显示bucket list长度的柱状图。

-v
--version 显示readelf的版本信息。

-H
--help 显示readelf所支持的命令行选项。

-W
--wide 宽行输出。

@file 可以将选项集中到一个文件中,然后使用这个@file选项载入。

[举例]
先给出如下例子:
1,对于可执行文件形式的elf格式文件:
1)查看可执行程序的源代码如下:
[quietheart@lv-k cppDemo]$ cat main.cpp
#include <iostream>
using std::cout;
using std::endl;
void my_print();

int main(int argc, char *argv[])
{
my_print();
cout<<"hello!"<<endl;
return 0;
}

void my_print()
{
cout<<"print!"<<endl;
}

2)编译如下:
[quietheart@lv-k cppDemo]$ g++ main.cpp -o main
[quietheart@lv-k cppDemo]$ g++ -g main.cpp -o main.debug

3)编译之后,查看生成的文件:
[quietheart@lv-k cppDemo]$ ls -l
总计 64
-rwxr-xr-x 1 quietheart quietheart 6700 07-07 18:04 main
-rw-r--r-- 1 quietheart quietheart 201 07-07 18:02 main.cpp
-rwxr-xr-x 1 quietheart quietheart 38932 07-07 18:04 main.debug
这里,main.debug是带有调试信息的可执行文件,main是一般的可执行文件。

2,对于库文件形式的elf格式文件:
1)查看库的源代码如下:
//myfile.h
#ifndef __MYFILE_H
#define __MYFILE_H
void printInfo();
#endif

//myfile.cpp
#include "myfile.h"
#include <iostream>
using std::cout;
using std::endl;
void printInfo()
{
cout<<"hello"<<endl;
}
2)编译如下:
[quietheart@lv-k bak]$ g++ -c myfile.cpp
[quietheart@lv-k bak]$ g++ -shared -fPCI -o libmy.so myfile.o
[quietheart@lv-k bak]$ ar -r libmy.a myfile.o
ar: creating libmy.a

3)编译之后,查看生成的文件:
[quietheart@lv-k bak]$ ls -l
总计 44
-rw-r--r-- 1 quietheart quietheart 2154 07-08 16:14 libmy.a
-rwxr-xr-x 1 quietheart quietheart 5707 07-08 16:08 libmy.so
-rwxr-xr-x 1 quietheart quietheart 117 07-08 16:06 myfile.cpp
-rwxr-xr-x 1 quietheart quietheart 63 07-08 16:08 myfile.h
-rw-r--r-- 1 quietheart quietheart 2004 07-08 16:08 myfile.o
libmy.a libmy.so myfile.cpp myfile.h myfile.o
这里,分别生成目标文件myfile.o,共享库文件libmy.so,和静态库文件libmy.a。

阅读全文

与查看elf程序编译参数相关的资料

热点内容
voc文件夹 浏览:862
租广东联通服务器注意什么云空间 浏览:932
javascript高级程序设计pdf 浏览:289
pwm单片机原理 浏览:346
ai算法在线修复图片 浏览:979
scratch编程中如何做射击游戏 浏览:476
at89c51编程器 浏览:341
项目经理叫醒程序员 浏览:342
autocad旋转命令 浏览:660
手机版wpsoffice怎么打包文件夹 浏览:579
在成都学车用什么app 浏览:818
grep命令管道 浏览:426
java修改重启 浏览:567
单片机供电方案 浏览:770
airpodspro一代怎么连接安卓 浏览:218
豌豆荚app上有什么游戏 浏览:285
公路商店app标签选什么 浏览:339
linuxoracle命令行登录 浏览:227
android深度休眠 浏览:173
php微信开发例子 浏览:846