elf

Can I change 'rpath' in an already compiled binary?

大憨熊 提交于 2019-12-17 07:01:47
问题 I have an old executable that's scheduled for the scrap heap, but it's not there yet. It relies on some libs that have been removed from my environment, but I have some stub libs someplace where it works fine. Id like to point this executable to these stub libs. Yes, i could set LD_LIBRARY_PATH, but this executable is called from many scripts, and many users and I'd love to fix it in one spot. I don't have source for this, and would be hard to get it. I was thinking - can I edit this file,

Why GCC compiled C program needs .eh_frame section?

筅森魡賤 提交于 2019-12-17 06:34:16
问题 Test is on 32 bit x86 Linux with gcc 4.6.3 When using gcc to compile a C program and using readelf to check the section info, I can see the .eh_frame section and .eh_frame_hdr sections inside. For example, here is the section info of binary program Perlbench . readelf -S perlbench There are 28 section headers, starting at offset 0x102e48: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 08048154 000154 000013 00 A 0

What is the meaning of the ES, Lk, Inf and Al column headers in the output of readelf -S?

和自甴很熟 提交于 2019-12-14 03:42:14
问题 In the outupt of readelf -S , I'd like to know what the column headers ES , Lk , Inf and Al mean. For example: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000034 00000d 00 AX 0 0 4 [ 2] .rel.text REL 00000000 000394 000008 08 10 1 4 [ 3] .data PROGBITS 00000000 000044 000000 00 WA 0 0 4 [...] 回答1: I'd like to know what the column headers ES, Lk, Inf and Al Look in /usr/include/elf.h, for definition of

ELF loading when VMA != LMA

旧街凉风 提交于 2019-12-14 02:25:44
问题 I have a problem on this one. I am using ARM Cortex-A9 with DS-5 to create baremetal firmware. I modified my linker file to intentionally put the .data section LMA adjacent to the text and rodata sections, because its default run-time VMA is located 1MB away and the .bin image is around 1MB but containing 90% zeroes. And so I intentionally made LMA != VMA to save space. I also added a code in start.S that relocates the .data section from its lma to vma. However on loading the resulting elf

Using $ORIGIN to specify the interpreter in ELF binaries isn't working

亡梦爱人 提交于 2019-12-14 01:11:12
问题 I'm using patchelf to modify rpath and the interpreter for already compiled binaries. The calls to patchelf look something like this: patchelf --set-interpreter "\$ORIGIN/lib/ld-linux-x86-64.so.2" --set-rpath "\$ORIGIN/lib" ./grep These are being set correctly, as verified by running readelf -l ./grep | grep interpreter , which outputs: [Requesting program interpreter: $ORIGIN/lib/ld-linux-x86-64.so.2] When I try to run the executable, however, I get the following error: -bash: ./grep: No

Accessing .eh_frame data during execution

浪子不回头ぞ 提交于 2019-12-14 00:24:30
问题 This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . I'm trying to access the contents of .eh_frame section of a running program from within it (specifically, the program is Linux kernel 2.6.34.8). The .eh_frame contains useful data used for exception handling and I'd like to use it internally from within kernel code. The section is already being written by gcc ( readelf -a vmlinux.o contains .eh_frame ), the problem

Switch to and from 16-bit Real Mode and 32-bit Protected Mode

那年仲夏 提交于 2019-12-13 17:51:45
问题 I'm interested in writing my own microkernel with graphics support. However, as far as I know there is no way to change the graphics mode without interrupt 0x10 , which requires Real Mode. How can I switch between Real and Protected Mode during the application's runtime? I have seen an article on osdev.org, but since I am new to assembly I cannot work out how to implement this. Technical details: Ubuntu 16.04.4 LTS GCC 7.3.0 cross-compiler (i686-elf) NASM 2.11.08 assembler, but inline GAS

ELF Relocation reverse engineering

為{幸葍}努か 提交于 2019-12-13 14:28:28
问题 I am hoping you guys could help me understand how relocation entries and ELF section data are related, and how it is all processed and generated. I have an ancient unsupported tool that takes an ELF file and a related PLF file (partially linked file, generated earlier in the build process) and builds a custom relocatable file from it that is used on a platform (PPC) with tight memory constraints. This works fine except that it contains about a meg of initialization code that we want to unload

How can I get the symbol name in struct “Elf64_Rela”

北城以北 提交于 2019-12-13 12:34:11
问题 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mman.h> #include <errno.h> #include <fcntl.h> #include <elf.h> Elf64_Rela *retab; Elf64_Rela *retab_end; Elf64_Ehdr *ehdr; Elf64_Shdr *shdr; char *strtab; void elf_open(char *filename) { int fd = open(filename, O_RDONLY); struct stat sbuf; fstat(fd, &sbuf); void *maddr = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); close(fd); ehdr = maddr; shdr =

Flags in objdump output of object file

喜你入骨 提交于 2019-12-13 11:57:24
问题 There is this output of objdump on some object file: $ objdump -h main.o main.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000000b 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000000 00000000 00000000 00000040 2**2 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 00000040 2**2 ALLOC 3 .note.GNU-stack 00000000 00000000 00000000 00000040 2**0 CONTENTS, READONLY, CODE What do these flags CONTENTS, ALLOC, LOAD and