Comments (5)
Wow, good job finding this old bug. Hope the info in it helped.
I can't be of much assistance to verifying your fix since I filed this in reference to a problem I hit at my day job... which I left 4 years ago. I don't have access to the codebase where I was seeing this problem occur.
from patchelf.
Here is an example of what I'm talking about on a trivial "Hello, World" executable. Before:
$ objdump -x -j .dynamic a.out | tail
Sections:
Idx Name Size VMA LMA File off Algn
20 .dynamic 000001d0 0000000000600e28 0000000000600e28 00000e28 2**3
CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
0000000000600e28 l d .dynamic 0000000000000000 .dynamic
0000000000600e28 l O .dynamic 0000000000000000 _DYNAMIC
So this shows that the .dynamic
section is at file offset 0xe28 and will end up mapped at 0x600e28. In the symbol table there is both a debugging symbol called .dynamic
and also an object symbol called _DYNAMIC
that both point to this section.
Then if I run patchelf on this binary, we'll see this change:
$ patchelf --set-rpath '$ORIGIN/../lib' a.out
$ objdump -x -j .dynamic a.out | tail
Sections:
Idx Name Size VMA LMA File off Algn
0 .dynamic 000001e0 00000000003ff270 00000000003ff270 00000270 2**3
CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000003ff270 l d .dynamic 0000000000000000 .dynamic
0000000000600e28 l O .dynamic 0000000000000000 _DYNAMIC
So the section has now been relocated, both in the file and in virtual address space. The debugging symbol .dynamic
is also updated. However the object symbol _DYNAMIC
still has its old value and isn't pointing into this ELF table anymore.
from patchelf.
I suspect this behavior is related to this "FIXME" comment in ElfFile<ElfFileParamNames>::rewriteHeaders
:
/* Rewrite st_value. FIXME: we should do this for all
types, but most don't actually change. */
if (ELF32_ST_TYPE(rdi(sym->st_info)) == STT_SECTION)
wri(sym->st_value, rdi(shdrs[newIndex].sh_addr));
Presumably _DYNAMIC
will be STT_OBJECT
instead...
from patchelf.
This fix would probably look something a little like:
/* Rewrite st_value. */
if (ELF32_ST_TYPE(rdi(sym->st_info)) == STT_SECTION) {
wri(sym->st_value, rdi(shdrs[newIndex].sh_addr));
} else if (replacedSections.find(section) != replacedSections.end()) {
wri(sym->st_value, rdi(shdrs[newIndex].sh_addr));
}
...however, that only works for the special case that the symbol points to the beginning of the beginning of the section. What we really want is something that looks like:
Elf_Addr addr = rdi(sym->st_value);
addr -= OLD_START_ADDRESS_OF_SECTION;
addr += rdi(shdrs[newIndex].sh_addr));
wri(sym->st_value, addr);
I dug around and its not clear if the original address of the section is kept around anywhere though...
from patchelf.
Alright, got some progress here!
As it turns out, updating the symbol is not sufficient, because at least GCC-generated code seems to also rely on the .rela.dyn
section to fill-in references to the symbol, so patchelf also needs to update that as well - but having done so, it seems that this problem is solved and the program from SO works.
Somewhat unfortunately, this doesn't actually fix the underlying issue with NodeJS (and pcloud, in my case), so on to investigating further 🔍
from patchelf.
Related Issues (20)
- Test regression in 0.18.0: repeated-updates.sh, replace-add-needed.sh HOT 5
- patchelf breaks dylibs from recent Firefox Nightly builds HOT 11
- repeated-updates.sh fails on mips64el HOT 1
- What versions support redhat6
- `patchelf --set-interpreter` and `patchelf --set-rpath` depend on the order (at least on i686-linux) HOT 3
- Allow --rename-dynamic-symbols to change the version tag.
- Regression in 0.18.0: --set-rpath creates broken header alignment HOT 3
- `patchefd --set-rpath ... nodejs` broken since ~0.17.2 (0.15.0 works) HOT 3
- when I use zsh plugins zsh-autosuggestions, it something wrong HOT 1
- Program header editing features HOT 5
- SEGV when ELF has a malformed .dynamic section
- Relocatable binaries not handled
- Patchelf 0.18.0 Build failure on s390x with "span : out of range error"
- build failed for NetBSD
- rename-dynamic-symbols produces unusable binary
- Need help for cross-compliling libc.so.6
- patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections HOT 1
- _arguments:463: command not found: dynamic HOT 6
- `replace-needed.sh` test fails on 32-bit arm
- [RISCV] Error on 'make check' - relocation truncated to fit: R_RISCV_RVC_LUI against `__TMC_LIST__'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from patchelf.