Zachary Turner via llvm-dev
2018-Jul-23 04:31 UTC
[llvm-dev] Relinking (syscall-free) ELF executable into Mach-O and PE executables
Couldn’t you write the relocations to the ELF executable? I don’t know if current linkers have support for this, but it seems possible in theory to make a relinkable executable. If you want to do this with an already linked executable though, then yea this won’t be possible. On Fri, Jul 20, 2018 at 10:30 AM Reid Kleckner via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Typically people do this kind of thing by writing a loader for the > executable format you want to run, and they create libc stubs that either > delegate or reimplement enough functionality to get the app in question to > run. Wine, for example, uses this approach. It loads native PE executables, > and implements enough of the win32 API to run some applications. > > "Re-linking" would be tough because linking typically throws away static > relocations that you would need. > > On Fri, Jul 20, 2018 at 12:46 AM ardi via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi, >> >> Let's suppose we have an ELF executable that doesn't issue any syscall >> (I mean, syscalls are issued from an external dynamic library, not >> from the executable, and we can ignore such dynamic library because we >> have the proper equivalent library with the proper syscalls in MacOS >> and Windows). >> >> So, the question: Is it "currently possible" (by "currently possible" >> I mean that all the needed tools/code already exist) to somehow >> "unlink" the code and data from the ELF executable, and relink it as >> two new executables: one Mach-O and another PE? >> >> Would this be possible with just LLVM tools, or would other >> libraries/tools also be needed? >> >> Thanks a lot! >> >> ardi >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180722/b68b7bc4/attachment.html>
Pavel Labath via llvm-dev
2018-Jul-23 10:10 UTC
[llvm-dev] Relinking (syscall-free) ELF executable into Mach-O and PE executables
On Mon, 23 Jul 2018 at 05:31, Zachary Turner via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Couldn’t you write the relocations to the ELF executable? I don’t know if current linkers have support for this, but it seems possible in theory to make a relinkable executable. If you want to do this with an already linked executable though, then yea this won’t be possible.You can do a "ld --relocatable" to create an elf file that can be used as further input to the linker (so relocations will be preserved, etc.). However, that file will not be a fully functional executable until you do a final non-relocatable link on it.
Zachary Turner via llvm-dev
2018-Jul-23 15:15 UTC
[llvm-dev] Relinking (syscall-free) ELF executable into Mach-O and PE executables
I was actually proposing something like where you write a fully working executable (identical to what the linker writes today), but you *additionally* write an extra section that contained information about the type and location of all applied relocations. This way you could re-write relocations on a subsequent link where the executable was used as an input. I don't know if any linkers currently have a mode where you can do this though, and it sounds like OP might want to use only functionality that is currently available in an existing linker today. On Mon, Jul 23, 2018 at 3:10 AM Pavel Labath <labath at google.com> wrote:> On Mon, 23 Jul 2018 at 05:31, Zachary Turner via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > > > Couldn’t you write the relocations to the ELF executable? I don’t know > if current linkers have support for this, but it seems possible in theory > to make a relinkable executable. If you want to do this with an already > linked executable though, then yea this won’t be possible. > > You can do a "ld --relocatable" to create an elf file that can be used > as further input to the linker (so relocations will be preserved, > etc.). However, that file will not be a fully functional executable > until you do a final non-relocatable link on it. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180723/38b495d9/attachment.html>