静态库和可重定位目标文件有什么区别?或者在动态库和共享对象文件之间.
如果它不相等的东西,什么有动态库,允许链接它,但共享对象文件不?
我正在使用 ARM-GCC 4.7.4 为 Cortex-M4 编译代码。对于我们的调试工具,我需要有关人类可读格式(例如 .txt)的所有变量的名称、类型和地址的知识。地图文件提供了大部分信息,遗憾的是没有提供如下结构内容:
typedef struct { float32_t Ref; // Input: Reference Value
float32_t Fdb; // Variable: Feedback Value
float32_t Err; // Input: Control Error
float32_t Kp; // Parameter: Gain of the Proportional Part
float32_t Up; // Output: Output of Proportional Part
float32_t Ki; // Parameter: Gain of the Integral Part
float32_t Ui; // Output: Output of the Integral Part
float32_t OutPreSat; // Output: Not saturated Output
float32_t OutMax; // Parameter: Maximum Output
float32_t OutMin; // Parameter: …Run Code Online (Sandbox Code Playgroud) 我对内核如何加载到内存中有一些疑问。经过检查,/proc/kallsyms我能够找到内核中各种符号的地址。
$ cat /proc/kallsyms | head -n 10
00000000 t __vectors_start
80008240 T asm_do_IRQ
80008240 T _stext
80008240 T __exception_text_start
80008244 T do_undefinstr
80008408 T do_IPI
8000840c T do_DataAbort
800084a8 T do_PrefetchAbort
80008544 t gic_handle_irq
800085a0 T secondary_startup
Run Code Online (Sandbox Code Playgroud)
puts在 0x200 的偏移量处说函数。当加载到内存 at 说地址时0x8048000,我将能够puts在0x8048000 + 0x200. 内核也一样吗?即内核映像是否作为 1 个连续.text部分加载到内存中?出于好奇,我今天尝试运行此代码(使用 编译gcc -m32 1.c):
int main(void)
{
// EB is the opcode for jmp rel/8
// FE is hex for -2
// So this is essentially an infinite loop
((void(*)(void))"\xEB\xFE")();
}
Run Code Online (Sandbox Code Playgroud)
......它奏效了!没有段错误,程序(正确?)进入无限循环。查看反汇编 ( objdump -d a.out),您可以看到对...的调用,无论地址是什么0x8048480:
080483d6 <main>:
....
80483e7: b8 80 84 04 08 mov $0x8048480,%eax
80483ec: ff d0 call *%eax
....
Run Code Online (Sandbox Code Playgroud)
objdump -s -j .rodata a.out 给出:
Contents of section .rodata:
8048478 03000000 01000200 ebfe00 ...........
~~~~
Run Code Online (Sandbox Code Playgroud)
所以它确实在执行存储在.rodatasection中的字符串。所以我跑了readelf --sections a.out …
我有一个静态库libfoo.a,它只是多个.o文件的压缩。我正在寻找一种列出所有符号的方法
这样我就可以找出这个库的所有外部符号依赖项。
我遇到了size命令,它给出了ELF文件的节大小.在玩它时,我为最简单的C++程序创建了一个输出文件:
int main(){return 0;}
Run Code Online (Sandbox Code Playgroud)
显然,我没有定义任何初始化或未初始化的数据,那么为什么我的BSS和DATA部分的大小为512和8字节?
我以为可能是因为int main(),我尝试为以下C程序创建目标文件:
void main(){}
Run Code Online (Sandbox Code Playgroud)
对于BSS和DATA部分,我仍然没有得到0.
是因为某些最小尺寸的内存被分配给那些部分?
编辑 - 我认为这可能是因为链接库,但我的对象是动态链接所以可能不应该是问题
我读过的关于 ELF 标头魔法的每一个资源都指出它包含 ASCII 编码的“ELF”,然后简要提到 0x7F 被添加到它前面而没有解释。
0x7F 有原因吗?
是为了避免与现有格式发生冲突吗?现有标准合规性?用于检测有关磁盘或内存的内容?
有一个为语言研究开发的程序(http://people.csail.mit.edu/mcollins/code.html)。当我尝试在 Windows 上使用 Git bash 终端运行解析器时,出现错误:
bash: cannot execute binary file: Exec format error.
Run Code Online (Sandbox Code Playgroud)
首先,我认为这是因为我的 64 位操作系统,因为该文件是 32 位的。因此,我在 32 位系统上尝试了该程序,但得到了相同的消息。
关于如何解决这个问题有什么想法吗?:
file (program)显示:
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.2.5, with debug_info, not stripped
Run Code Online (Sandbox Code Playgroud)
uname -srv对于我的 64 位操作系统,显示:
MINGW64_NT-10.0-19042 3.1.7-340.x86_64 2021-03-26 22:17 UTC
Run Code Online (Sandbox Code Playgroud)
uname -srv对于我的 32 位操作系统,显示:
MINGW32_NT-6.1-7601 3.1.7-340.i686 2021-03-26 22:01 UTC
Run Code Online (Sandbox Code Playgroud)
PS:如果你想尝试一下,这段代码应该可以在程序目录中运行,但它对我不起作用:
gunzip -c models/model2/events.gz | code/parser examples/sec23.tagged models/model2/grammar 10000 1 1 1 1 …Run Code Online (Sandbox Code Playgroud) 我有这样的目录结构
dir1
one.c
two.c
dir2
three_main.c
four.c
Run Code Online (Sandbox Code Playgroud)
我需要libdir1.so从所有c文件中创建一个共享库,并从所有c文件中dir1
创建一个可执行文件以及my_exedir2libdir1.so
我分两步创建.so和可执行文件。
.so step1: gcc -c -fPIC -g -O2 -pthread -o one.o one.c
gcc -c -fPIC -g -O2 -pthread -o two.o two.c
.so step2: gcc -shared -g -O2 -pthread -o libdir1.so one.o two.o
exe step1: gcc -c -fPIE -o three_main.o three_main.c
gcc -c -fPIE -o four.o four.c
exe step2: gcc -Wall -g -L -ldir1 -o my_exe three_main.o four.o
Run Code Online (Sandbox Code Playgroud)
现在我的问题是...... …
elf ×10
linux ×4
c ×2
gcc ×2
linux-kernel ×2
arm ×1
bash ×1
binaryfiles ×1
c++ ×1
compilation ×1
debugging ×1
executable ×1
linker ×1
mach-o ×1
memory ×1
objdump ×1
object-files ×1
paging ×1
unix ×1
windows ×1
x86 ×1