GithubHelp home page GithubHelp logo

polyfill-glibc's Introduction

polyfill-glibc

How often have you compiled a C/C++ program on a recent Linux system, tried to run that compiled program on an older Linux system, and then hit a GLIBC version error? Concretely, perhaps you're seeing something like this:

new-system$ gcc my-program.c -o my-program
old-system$ scp new-system:my-program .
old-system$ ./my-program
./my-program: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by ./my-program)

The motivating idea behind polyfill-glibc is that an extra post-compilation step can prevent these errors from happening:

new-system$ gcc my-program.c -o my-program
new-system$ polyfill-glibc --target-glibc=2.17 my-program
old-system$ scp new-system:my-program .
old-system$ ./my-program
It works!

Build and run instructions

To build polyfill-glibc, you'll need a git client, a C11 compiler (such as gcc), and ninja. With these tools present, the build process is:

$ git clone https://github.com/corsix/polyfill-glibc.git
$ cd polyfill-glibc
$ ninja polyfill-glibc

Once built, running it is intended to be as simple as passing the oldest version of glibc you want to support, along with the path to the program (or shared library) to modify, as in:

$ ./polyfill-glibc --target-glibc=2.17 /path/to/my-program

If running it isn't this simple, then open a GitHub issue describing why not, and we'll try to improve things.

Note that at present, the --target-glibc operation of polyfill-glibc is only implemented for x86_64 and aarch64. If other architectures are of interest to you, open a GitHub issue so that we can gauge demand.

If distributing shared libraries, polyfill-glibc can also be used to inspect dependencies (with the --print-imports and --print-exports operations), and to modify how shared libraries are loaded (with the --set-rpath, --set-runpath, and --set-soname operations). Consult the documentation for a full list of command line options.

License

polyfill-glibc itself is made available under the MIT license. The polyfilling procedure can sometimes involve linking small pieces of polyfill-glibc into the file being modified; the "the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software" clause of the MIT license is explicitly waived for any such pieces.

polyfill-glibc's People

Contributors

corsix avatar

Stargazers

Lorenzo Mangani avatar Saulius Krasuckas avatar  avatar Jack avatar Dom avatar Logyi, hajnalvédő avatar Jacob Kiesel avatar Исаак Алексеевич avatar ^_^ avatar nil avatar ahdg avatar aubrey avatar William Zhang avatar TimeFunny avatar  avatar Suavesito avatar Yupei Qi avatar Thomas Fransham avatar Anatoly Chernov avatar Rafael Ristovski avatar  avatar  avatar Javier Tia avatar Axel Pahl avatar compwron avatar Alexander Monakov avatar  avatar Lech Perczak avatar Turo Lamminen avatar Alireza |S.N| avatar Kerim Güven avatar Alex Hughes avatar Souvik Sen avatar le Duc Banal avatar Alexander Bonin avatar Tsvetomir Bonev avatar Elliot Cameron avatar Rafael Julio avatar bobozhengsir avatar Andrew Jeffery avatar  avatar Joel Stanley avatar David Jansen avatar Raphaël BOICHOT avatar  avatar  avatar Sebastian Elsner avatar Jean-Christophe Morin avatar jadon avatar Noel Kwan avatar wcchoi avatar Scott Opell avatar Olivier Chassé St-Laurent avatar Jonathan Curran avatar Jing Yen avatar Sander in 't Hout avatar user avatar Roc Vallès i Domènech avatar eli avatar Arthur Minasyan avatar Luis Lavena avatar Wilfred Hughes avatar Yuxiang Qiu avatar NCM avatar  avatar Jitesh Nayak avatar rohit sohlot avatar Jeffrey H. Johnson avatar James Milne avatar Kate avatar  avatar John Murray avatar Siddharth Chintamaneni avatar  avatar Caleb Deveraux avatar Aneesh Durg avatar James D avatar Garrett Bluma avatar Dario Vladović avatar ZH王 avatar Wesley Moore avatar Evan McBroom avatar bryfry avatar Aman Gupta Karmani avatar Brad Svercl avatar Stephen Santino avatar Jinghao Jia avatar Val Packett avatar Ben Simms avatar Ignacy Koper avatar Tiago Cogumbreiro avatar Nikhil avatar Henrik avatar Sam Elliott avatar Christopher Grim avatar  avatar ilobilo avatar Alexander Qi avatar Farooq Karimi Zadeh avatar Simon Engledew avatar

Watchers

 avatar Lucian avatar Adhemerval Zanella avatar Denis Golovan avatar Pablo Baeyens avatar

Forkers

invokesus qxip

polyfill-glibc's Issues

Strip breaks some processed binaries

Example:

$ ninja
$ cp polyfill-glibc out

$ ./polyfill-glibc --remove-kernel-version --add-hash --add-gnu-hash --remove-debug ./out
$ ./out
No input file(s) specified.

$ strip out
$ ./out
[1]    1807806 segmentation fault  ./out

Using sstrip produces the following output:

sstrip: out: File too large
sstrip: out: ELF file may have been corrupted!

Run polyfill on itself after compiling

I was recently using polyfill on a project and included my compiled build of polyfill in the GitHub project so that GitHub actions could output a polyfilled binary (my project for reference).

However since I compiled polyfill on a modern system (fedora 40) glibc was newer than the version ubuntu container actions uses. The fix ofc was very simple, just run polyfill on itself! I was able to patch polyfill for glibc for 2.2.5 and everything is now working great.

I think it would be very handy! (And thanks for this wonderful tool!)

Multiple libraries having issues moving earlier than 2.38

I get the following when I try to process a bunch of libraries in something I'm trying to pack up

Cannot change target version of ./libSDL2-2.0.so.0 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcat@GLIBC_2.38
  strlcpy@GLIBC_2.38
  wcslcat@GLIBC_2.38
  wcslcpy@GLIBC_2.38
Cannot change target version of ./libkrb5support.so.0 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcpy@GLIBC_2.38
Cannot change target version of ./libk5crypto.so.3 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcpy@GLIBC_2.38
Cannot change target version of ./libpangoft2-1.0.so.0 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcpy@GLIBC_2.38
Cannot change target version of ./libglib-2.0.so.0 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcat@GLIBC_2.38
  strlcpy@GLIBC_2.38
Cannot change target version of ./libgio-2.0.so.0 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcpy@GLIBC_2.38
Cannot change target version of ./libkrb5.so.3 to 2.35 (x86_64) due to missing knowledge about how to handle:
  strlcpy@GLIBC_2.38

System is using 2.39, and I was targeting 2.35

Glibc 2.38 fscanf error

Hi

I am trying to change required glibc for manually built recent LuaJIT under 2.38.
However all I get is:

$ polyfill-glibc --target-glibc=2.36 ./libluajit.so 
Cannot change target version of ./libluajit.so to 2.36 (x86_64) due to missing knowledge about how to handle:
  __isoc23_fscanf@GLIBC_2.38

Checked under 918c681 commit.
Is it something worth reporting?

Add license file

Foremost: really nice project! Thanks for it.

I'm building a recipe for polyfill-glibc for Yggdrasil, the Julia language binary builder recipe book. To be accepted, it needs to have a LICENSE file; which is missing from the current repo structure.

Aarch64 support

A great many projects for me both professionally and personally make use of aarch64 processors. I’d love to see support for it added to this project.

Polyfill for `__cxa_thread_atexit_impl@GLIBC_2.18` and `quick_exit@GLIBC_2.24` Missing for Target Glibc 2.17

Hello,

I am attempting to polyfill a binary named bun with the target glibc version set to 2.17 using the polyfill-glibc tool. However, I encountered an error indicating that the tool lacks the necessary knowledge to handle two specific symbols:

  1. __cxa_thread_atexit_impl@GLIBC_2.18
  2. quick_exit@GLIBC_2.24

The error message is as follows:

$ ./polyfill-glibc --target-glibc=2.17 ./bun
Cannot change target version of ./bun to 2.17 (x86_64) due to missing knowledge about how to handle:
  __cxa_thread_atexit_impl@GLIBC_2.18
  quick_exit@GLIBC_2.24

It appears that the current implementation of polyfill-glibc does not support these symbols for the target glibc version I specified. Could you please advise on whether there is a workaround for this issue or if there are plans to add support for these symbols in future updates?

NOT AN ISSUE (feel free to close)

Hi, since there is no way on Github to give authors praise for their projects, please excuse me for abusing the issue tracker, since I really wanted to let you know how great and useful this project is.
I frequently write programs that need to run on an in-house compute cluster with a quite old Centos. So far the only compiled language whose programs would run on the cluster when compiled locally on my Ubuntu Laptop were Go programs (as advertised). For all other languages, I would need to install the development env on the cluster and compile the programs there, which in the case of Rust, would take really long, because of the not-so-great performance of the cluster head node.
Now, with your project, I was able to transform Rust programs and even AOT-compiled C# programs to run directly on the cluster, after having been compiled on my Laptop. This is a really great life improvement for me.

Thanks a lot for this cool project!

KR Axel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.