elf

CMake: Embed ELF into executable

亡梦爱人 提交于 2019-12-03 08:34:28
I have a project that needs access to an ELF file embedded into the executable in a special section . I was handcrafting Makefiles before and simply had a shell script where I used objcopy to copy the target I wanted to embed into an .o file, then link to this file in the executable. # Create a new section and copy the binary there ($1=input $2=output name) objcopy --input-target binary --output-target elf64-x86-64 \ --binary-architecture i386 $1 $2.o Now I want to get rid of the custom Makefiles and use CMake to generate them. However, I don't see an easy way to link to such a file. I am able

Linux user-space ELF loader

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 07:25:22
问题 I need to do a rather unusual thing: manually execute an elf executable. I.e. load all sections into right places, query main() and call it (and cleanup then). Executable will be statically linked, so there will be no need to link libraries. I also control base address, so no worries about possible conflicts. So, is there are any libraries for that? I found OSKit and its liboskit_exec, but project seems to be dead since 2002. I'm OK with taking parts of projects (respecting licenses, of

Usage differences between. a.out, .ELF, .EXE, and .COFF

a 夏天 提交于 2019-12-03 07:21:19
问题 Don't get me wrong by looking at the question title - I know what they are (format for portable executable files). But my interest scope is slightly different MY CONFUSION I am involved in re-hosting/retargeting applications that are originally from third parties. The problem is that sometimes the formats for object codes are also in .elf, .COFF formats and still says, "Executable and linkable". I am primarily a Windows user and know that when you compile and assemble your C/C++ code, you get

Unresolvable `R_X86_64_NONE` relocation

情到浓时终转凉″ 提交于 2019-12-03 06:57:24
I'm using Devtoolset-7 on CentOS 7 and have built Boost 1.65.1 w/ it. But when I link my application, I've got the following: /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: /opt/rh/devtoolset-7/root/usr/lib64/libboost_unit_test_framework.a(compiler_log_formatter.o)(.text._ZN5boost9unit_test5utils11string_castINS0_13basic_cstringIKcEEEESsRKT_[_ZN5boost9unit_test5utils11string_castINS0_13basic_cstringIKcEEEESsRKT_]+0x3c): unresolvable R_X86_64_NONE relocation against symbol `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64

How to convert PE(Portable Executable) format to ELF in linux

点点圈 提交于 2019-12-03 06:19:13
问题 What's the best tool for converting PE binaries to ELF binaries? Following is a brief motivation for this question: Suppose I have a simple C program. I compiled it using gcc for linux(this gives ELF), and using 'i586-mingw32msvc-gcc' for Windows(this gives a PE binary). I want to analyze these two binaries for similarities, using Bitblaze's static analysis tool - vine(http://bitblaze.cs.berkeley.edu/vine.html) Now vine doesn't have a good support for PE binaries, so I wanted to convert PE-

String table in ELF

蓝咒 提交于 2019-12-03 06:16:09
I get some symbol and I get the hexedit of an elf file. How can I know in which section this symbol appear? What is the different between strtab and shstrtab ? there is also an array of symbol strings? When I get index in the names table, is it index in strtab or shstrtab ? Samir Baid For the first question, we would need the hexedit of the elf file to understand properly. For the second question - strtab stands for String Table shstrtab stands for Section Header String table. When we read ELF header, we see that every ElfHeader structure contains a member called e_shstrndx. This is an index

dumping C structure sizes from ELF object file

爱⌒轻易说出口 提交于 2019-12-03 06:08:07
问题 How can you extract the sizes of all C structures from an ELF object file with debugging symbols? Individual struct sizes can be obtained from GDB using "print sizeof(some_struct)", but what I need is to get a listing of all structures. I've looked at "nm" and "objdump", but I don't see options to do what I'm looking for. Is there a way to do this with standard Unix tools, or do I need to extract the debug symbol section from the ELF file and process it myself? I'm hoping it's not the latter.

Forcing certain compiler-generated variables into specific ELF sections (with gcc)

巧了我就是萌 提交于 2019-12-03 06:08:05
问题 I'll start with the ultimate question: In C with gcc, is it possible to get the value(s) of __func__ (or equivalently, __FUNCTION__ ) stored in a section other than .rodata (or wherever -mrodata= points) or subsection thereof? The full explanation: Say I have a logging macro: #define LOG(fmt, ...) log_internal(__FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__) (The string concatenation operator ## used in that unary context consumes the preceding comma if and only if the __VA_ARGS__ list is

executing init and fini

浪尽此生 提交于 2019-12-03 05:46:08
问题 I just read about init and fini sections in ELF files and gave it a try: #include <stdio.h> int main(){ puts("main"); return 0; } void init(){ puts("init"); } void fini(){ puts("fini"); } If I do gcc -Wl,-init,init -Wl,-fini,fini foo.c and run the result the "init" part is not printed: $ ./a.out main fini Did the init part not run, or was it not able to print somehow? Is there a any "official" documentation about the init/fini stuff? man ld says: -init=name When creating an ELF executable or

How to load a shared library without loading its dependencies?

孤街浪徒 提交于 2019-12-03 05:37:54
Say I have a library libfoo.so.1 , which depends (according to ldd ) on libbar.so.1 . However, libbar.so.1 is not available at the moment. My app needs to call a function in libfoo.so.1 which doesn't require libbar.so.1 at all. Is there a way to load libfoo.so.1 , resolve the function symbol and then call it without having libbar.so.1 to satisfy the dependency? It's a case of "I know what I'm doing, just let me do it already". I tried the RTLD_LAZY flag, but it still tries to load the libbar.so.1 library before not loading the symbols. EDIT Here's the exact situation. We have 3 players: libbar