elf

How to make static linked ELF file to load LD_PRELOAD .so

风格不统一 提交于 2019-12-01 05:14:56
问题 I have static linked binary (ELF file) it doesn't have dynamic segment, .dymsym sections and it doesn't perform LD_PRELOAD command and etc. How could i create fake dummy dynamic segment to activate dynamic loader and perform LD_PRELOAD command? 回答1: How could i create fake dummy dynamic segment to activate dynamic loader and perform LD_PRELOAD command? You can't. Even if you could, getting LD_PRELOAD to preload something would still be useless: usually you want to interpose some symbols in

What are the real ELF TLS ABI requirements for each cpu arch?

核能气质少年 提交于 2019-12-01 03:49:29
Ulrich Drepper's paper on thread-local storage outlines the TLS ABI for several different cpu architectures, but I'm finding it insufficient as a basis for implementing TLS for two reasons: It omits a number of important archs like ARM, MIPS, etc. (while including a bunch of completely-irrelevant ones like Itanium) More importantly, it mixes a lot of implementation details with ABI, so that it's hard to tell which properties are required for interoperability, and which are just aspects of his implementation. As an example, the only actual ABI requirements for i386 are: %gs:0 points to a

dladdr doesnt return the function name

荒凉一梦 提交于 2019-12-01 03:45:20
问题 I'm trying to use dladdr. It correctly locates the library, but it does not find the function name. I can call objdump, do a little math, and get the address of the function that I pass dladdr. If objdump can see it, why can't dladdr? Here is my function: const char *FuncName(const void *pFunc) { Dl_info DlInfo; int nRet; // Lookup the name of the function given the function pointer if ((nRet = dladdr(pFunc, &DlInfo)) != 0) return DlInfo.dli_sname; return NULL; } Here is a gdb transcript

How to change alignment of code segment in ELF

回眸只為那壹抹淺笑 提交于 2019-12-01 03:23:28
问题 In ELF binary, how to change the alignment of loadable segments? In the below example (See right corner), I want to reduce the 0x200000 to 0x40960. LOAD 0x000000 0x000000400000 0x0000000000400000 0x000704 0x000704 R E **0x200000** LOAD 0x000e10 0x000000600e10 0x0000000000600e10 0x000230 0x000238 RW **0x200000** Can any compiler expert (GCC or clang), provide me a solution for this? 回答1: I don't know if you really want to do that but you can change the max page size with ld -z max-page-size

COFF on Linux or ELF on Windows

浪子不回头ぞ 提交于 2019-12-01 03:14:06
Is it possible to run the COFF executable files on UNIX or the ELF executable files on Windows? And what would be the steps to be able to run either file type on Windows and UNIX. I'm just curious. To actually run executables and have them do useful stuff, you need to worry about the API, not just the executable file format. On a Linux machine with WINE installed, you can run Windows .EXE files from the command line and they do the same thing that they do on Windows. The other way around is not really possible, however if you install CYGWIN on a Windows machine, and then rebuild the

How to interpret the dynamic symbol table in an ELF executable?

我与影子孤独终老i 提交于 2019-12-01 00:02:30
问题 I was looking at interpreting the dynamic symbol table ( .dynsym ) of an ELF executable file. I could successfully interpret the symbol table .symtab (16 bytes for each symbol) using the value attribute to denote the address of the symbol and name attribute to denote the offset of the start of string in .strtab section. But I'm unable to interpret the dynamic symbol table ( .dynsym ) using the same method. I used Ali's blog [1] for reference. I looked at another blog of Ali's [2] but I'm not

How does ELF file format defines the stack?

半城伤御伤魂 提交于 2019-11-30 23:52:48
I'm studying the ELF file format, so I compiled a small program, dumped the section headers and their contents from the resulting executable. The ELF header contains the entry point address, which points into start of the .text section. I also found the .data section that contains the static data and .rodata that contains the read only data... I expect there is a section for the stack too, but I can't find that section. I also expect that at some point ESP is set to the top of some section but I can't find anything like that in the disassembly. So how does ESP gets its initial value? The

How to change alignment of code segment in ELF

风流意气都作罢 提交于 2019-11-30 22:30:29
In ELF binary, how to change the alignment of loadable segments? In the below example (See right corner), I want to reduce the 0x200000 to 0x40960. LOAD 0x000000 0x000000400000 0x0000000000400000 0x000704 0x000704 R E **0x200000** LOAD 0x000e10 0x000000600e10 0x0000000000600e10 0x000230 0x000238 RW **0x200000** Can any compiler expert (GCC or clang), provide me a solution for this? I don't know if you really want to do that but you can change the max page size with ld -z max-page-size=4096 : $ gcc foo.c && readelf -Wl ./a.out | grep LOAD LOAD 0x000000 0x0000000000400000 0x0000000000400000

Compile C program using dlopen and dlsym with -fPIC

一笑奈何 提交于 2019-11-30 21:29:59
I am having a problem about a wrong symbol resolution. My main program loads a shared library with dlopen and a symbol from it with dlsym. Both the program and the library are written in C. Library code int a(int b) { return b+1; } int c(int d) { return a(d)+1; } In order to make it work on a 64-bit machine, -fPIC is passed to gcc when compiling. The program is: #include <dlfcn.h> #include <stdio.h> int (*a)(int b); int (*c)(int d); int main() { void* lib=dlopen("./libtest.so",RTLD_LAZY); a=dlsym(lib,"a"); c=dlsym(lib,"c"); int d = c(6); int b = a(5); printf("b is %d d is %d\n",b,d); return 0;

How does ELF file format defines the stack?

半世苍凉 提交于 2019-11-30 18:10:40
问题 I'm studying the ELF file format, so I compiled a small program, dumped the section headers and their contents from the resulting executable. The ELF header contains the entry point address, which points into start of the .text section. I also found the .data section that contains the static data and .rodata that contains the read only data... I expect there is a section for the stack too, but I can't find that section. I also expect that at some point ESP is set to the top of some section