简体   繁体   English

在PLT部分中强制输入

[英]Force entries in PLT section

For reasons, I want to force some entries in the PLT section. 由于某些原因,我想强制在PLT部分中输入一些内容。 I 've managed to do this for some entries, however some functions are never inserted in PLT. 我已经设法对某些条目执行此操作,但是某些功能从未插入PLT中。

so, lets say that I have main.c : 因此,可以说我有main.c

int main(){
// some code
strcmp(a,b); //suppose a, b strings
// more code
// suppose that result of strcmp is used, so it won't be optimised away
}

and help.c : help.c

// declaration
void forceplt() __attribute__((__used__));
// definition
void forceplt(){
abs(-1);
__aeabi_dadd(0, 0);
}

Then, I compile and link the above two relocatable objects, into an executable object. 然后,我将以上两个可重定位的对象编译并链接到一个可执行对象中。 To make sure that the abs and dadd functions will remain in the PLT section, I compile helper.o using -O0 . 为了确保absdadd函数将保留在PLT部分中,我使用-O0编译helper.o main.o can be compiled with a higher level, lets say `-O1'. main.o可以进行更高级别的编译,比方说`-O1'。

On the executable object I would expect to see entries of all 3 functions: strcmp , abs , and dadd . 我希望在可执行对象上看到所有3个函数的条目: strcmpabsdadd However, this is not the case. 然而,这种情况并非如此。

Am I missing something here? 我在这里想念什么吗? Is it possible that linker omits some stuff because it figures out that they are never called? 链接器是否可能因为发现它们从未被调用而忽略了某些东西? Despite using O0 for helper, and used attribute for forceplt function? 尽管使用O0作为辅助函数,并使用了forceplt函数的属性?

Help me do a proper celebration of.. ten. 帮我适当地庆祝..十。 million. 百万。 questions! 问题!

Cheers! 干杯!

The abs and strcmp are recognized specially by GCC and it seems the compiler figures out that those calls are useless even in -O0 . absstrcmp被GCC特别识别,似乎编译器发现这些调用即使在-O0也无用。 If you look at the generate assembly ( gcc foo.c -S -o- ), you see that there is no corresponding call instruction. 如果查看generate程序集( gcc foo.c -S -o- ),则会看到没有相应的调用指令。

PLT entries are not generated by the compiler: they are not present in the .o files. PLT条目不是由编译器生成的:它们不在.o文件中。 They are generated by the link editor when they find a corresponding relocation in one of their input .o files. 当它们在输入的.o文件之一中找到对应的重定位时,它们由链接编辑器生成。 In order to generate a PLT entry, you need to generate a suitable relocation entry in one of your input .o files. 为了生成PLT条目,您需要在一个输入.o文件中生成一个合适的重定位条目。 A .o relocation always apply to a part of a section of the .o file: you need to have some memory bytes in some section of the some .o that you will relocate with a PLT-aware relocation. .o重定位始终适用于.o文件的一部分:您需要在某些.o某些部分中具有一些内存字节,然后使用支持PLT的重定位进行重定位。 It can by either an (possibly useless) instruction or some other (possibly useless) bytes. 它可以通过(可能无用)指令或其他一些字节(可能无用)来实现。

A solution is to create (in assembly) instructions which explicitly use the expected PLT entries. 一种解决方案是创建(汇编)明确使用预期的PLT条目的指令。 With x86_64 this can be done with: 使用x86_64可以通过以下方式完成:

  .text
  .type forceplt2,@function
forceplt2:
  callq abs@plt

I guess it's written like this in ARM: 我猜它是这样写的:

  .text
  .type forceplt2,%function
forceplt2:
  bl abs@plt

Or you can generate raw bytes for your relocation (on x86_64 again): 或者,您可以为重定位生成原始字节(再次在x86_64上):

   .data
   .align  8
   .type   forceplt3, @object
   .size   forceplt3, 8
 forceplt3:
   .quad   socket@GOTPLT

On x_86_64 , you should be able to use either @GOT , @GOTPLT , @GOTOFF , @GOTPCREL , @PLT or @PLTOFF . 在x_86_64上 ,您应该可以使用@GOT @GOTPLT@GOTOFF @GOTPCREL@PLT @GOTOFF@GOTPCREL@PLT@PLTOFF I'm not so sure how this is supposed to be written for ARM . 我不太确定该如何为ARM编写。

Any of these solutions will emit a suitable relocation entry which will cause the link editor to emit a PLT entry and a PLT GOT entry. 这些解决方案中的任何一个都会发出合适的重定位条目,这将导致链接编辑器发出PLT条目和PLT GOT条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GDB 在 PLT 部分显示错误的跳转地址 - GDB shows incorrect jump address at PLT section 当有多个定义时,函数何时在 GLIBC 中获取.plt 条目? - When do functions get .plt entries in GLIBC when there are multiple definitions? 如何了解“重定位”部分“ .rela.plt”的字段 - how to understand fields of Relocation section '.rela.plt' 可执行文件 object 中的 what's.rela.plt 部分? - what's .rela.plt section in executable object files? 阅读ELF二进制和打印功能虚拟地址的plt部分 - Read plt section of ELF binary and print function virtual address 在ELF或DWARF中,如何获取.PLT节值? —尝试获取检测工具所在位置的函数地址 - In ELF or DWARF, how can I get .PLT section values? — Trying to get the address of a function on where an instrumentation tool is in 为什么动态 ELF 文件中没有.rel.dyn/.got.plt 部分? - Why there are no .rel.dyn/.got.plt section in dynamic ELF files? 在运行时加载动态库会产生不一致和意外的结果、缺少符号和空 PLT 条目。 为什么? - Loading a dynamic library at run-time yields inconsistent and unexpected results, missing symbols and empty PLT entries. Why? 如何在ELF文件的.dynamic节中找到条目数? - How to find the number of entries in the .dynamic section of an ELF file? 强制 C 文件中的所有数据都在 .text(或其他)部分 - Force all data in a C file to be in .text (or other) section
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM