Thomas Fitzsimmons: Lisp ELF toolkit
作者尝试通过Common Lisp ELF库生成包含RPATH和RUNPATH的ELF二进制文件,在分析ELF结构后添加RUNPATH并成功生成测试文件,展示了Lisp环境的独特优势。 2025-4-18 04:35:46 Author: www.fitzsim.org(查看原文) 阅读量:7 收藏

Skip to content

I recently needed to generate an ELF binary with both RPATH and RUNPATH entries. I could not figure out how to produce this using linker command line arguments.

I was considering attempting a linker script, but first I switched to my Lisp REPL buffer 1 and found that (ql:quickload "elf") loaded a promising-looking Common Lisp ELF library.

I created a stub library with RPATH using gcc and an empty C file, then loaded it with (elf:read-elf).

With the SLIME inspector (M-x slime-inspect) I could traverse the structure of the ELF headers. I eventually found the RPATH entry.

In the REPL I built up a function to search for RPATH then push a new RUNPATH entry alongside it.

It turned out the ELF library had no support for the RUNPATH entry, so I redefined its dyn-tag dictionary to include it.

After adding RUNPATH, I wrote the modified ELF structures to a file using (elf:write-elf). The generated ELF file sufficed for the test case.

I thought this was an interesting use case to share, demonstrating unique properties of the Lisp environment. I published the result (I realize now I should have written generate-example-library.sh in Lisp instead of shell!; oh well).

  1. Which I have been trying to keep open lately, inspired by this post.

文章来源: https://www.fitzsim.org/blog/?p=767
如有侵权请联系:admin#unsafe.sh