History

ELF: Make first PT_LOAD cover headers

This makes it so that the first PT_LOAD segment covers ELF and program header and .interp (contained in the same page anyway, right before the start of the first loaded section). binutils strip creates invalid output otherwise (which strictly is a binutils bug, but let's be nice anyway).

Michael Matz committed 12 years ago

Commit f2c84911 parent a913ee61 file · +10 −5Browse files

Unified · Split

tccelf.c+10−5
@@ -1538,10 +1538,6 @@ static void tcc_output_binary(TCCState *s1, FILE *f, · 1537 unmodified lines
1538 }1538 }
1539}1539}
1540 1540
1541// making this evaluate to true allow valgrind to work on linux
1542// but when compiled with debug info and then striped
1543// the compiled programs segfault
1544// more tought must be applyed here
1545#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)1541#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1546#define HAVE_PHDR 11542#define HAVE_PHDR 1
1547#define EXTRA_RELITEMS 141543#define EXTRA_RELITEMS 14
@@ -1562,7 +1558,7 @@ void patch_dynsym_undef(TCCState *s1, Section *s) · 14 unmodified lines
1562 }1558 }
1563}1559}
1564#else1560#else
1565#define HAVE_PHDR 01561#define HAVE_PHDR 1
1566#define EXTRA_RELITEMS 91562#define EXTRA_RELITEMS 9
1567 1563
1568/* zero plt offsets of weak symbols in .dynsym */1564/* zero plt offsets of weak symbols in .dynsym */
@@ -1969,6 +1965,15 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 400 unmodified lines
1969 file_offset += s->sh_size;1965 file_offset += s->sh_size;
1970 }1966 }
1971 }1967 }
1968 if (j == 0) {
1969 /* Make the first PT_LOAD segment include the program
1970 headers itself (and the ELF header as well), it'll
1971 come out with same memory use but will make various
1972 tools like binutils strip work better. */
1973 ph->p_offset &= ~(ph->p_align - 1);
1974 ph->p_vaddr &= ~(ph->p_align - 1);
1975 ph->p_paddr &= ~(ph->p_align - 1);
1976 }
1972 ph->p_filesz = file_offset - ph->p_offset;1977 ph->p_filesz = file_offset - ph->p_offset;
1973 ph->p_memsz = addr - ph->p_vaddr;1978 ph->p_memsz = addr - ph->p_vaddr;
1974 ph++;1979 ph++;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t