Skip to content

Instantly share code, notes, and snippets.

@beakthoven
Last active May 4, 2025 12:55
Show Gist options
  • Save beakthoven/240736992abf0ea6f0ee1d8acb57a400 to your computer and use it in GitHub Desktop.
Save beakthoven/240736992abf0ea6f0ee1d8acb57a400 to your computer and use it in GitHub Desktop.
A script for patching toolchains to resolve glibc requirement issues on distros with old glibc packages. ( DEPRECATED ) ( FUNCTIONALITY MOVED TO https://github.com/Neutron-Toolchains/antman )
#!/usr/bin/env bash
WORK_DIR=$(pwd)
cd "$HOME" || exit
echo "Downloading patchelf binary from ArchLinux repos"
mkdir -p patchelf-temp
#curl -L https://github.com/Jebaitedneko/docker/raw/ubuntu/patchelf
curl -L https://archlinux.org/packages/community/x86_64/patchelf/download | bsdtar -C patchelf-temp -xf -
mv "$HOME"/patchelf-temp/usr/bin/patchelf "$HOME"/
rm -rf "$HOME"/patchelf-temp
echo "Downloading latest glibc from ArchLinux repos"
mkdir -p glibc
curl -L https://archlinux.org/packages/core/x86_64/glibc/download | bsdtar -C glibc -xf -
curl -L https://archlinux.org/packages/core/x86_64/lib32-glibc/download | bsdtar -C glibc -xf -
ln -svf "$HOME"/glibc/usr/lib "$HOME"/glibc/usr/lib64
echo "Patching glibc"
for bin in $(find "$HOME"/glibc -type f -exec file {} \; | grep 'ELF .* interpreter' | awk '{print $1}'); do
bin="${bin::-1}"
echo "Patching: $bin"
"$HOME"/patchelf --set-rpath "$HOME"/glibc/usr/lib --force-rpath --set-interpreter "$HOME"/glibc/usr/lib/ld-linux-x86-64.so.2 "$bin"
done
echo "Patching Toolchain"
for bin in $(find "$WORK_DIR" -type f -exec file {} \; | grep 'ELF .* interpreter' | awk '{print $1}'); do
bin="${bin::-1}"
echo "Patching: $bin"
"$HOME"/patchelf --add-rpath "$HOME"/glibc/usr/lib --force-rpath --set-interpreter "$HOME"/glibc/usr/lib/ld-linux-x86-64.so.2 "$bin"
done
echo "Cleaning"
rm -rf "$HOME"/patchelf
@Mikdadali
Copy link

this need to be paste in bashrc file sir?

@beakthoven
Copy link
Author

this need to be paste in bashrc file sir?

Uhh no, curl or wget this script inside your toolchain dir then open a terminal and execute it.

@Mikdadali
Copy link

Mikdadali commented Aug 16, 2022

i am using jenkins server sir, if i am using neutron 15 then this error will not come right sir? please confirm
Thanks

@beakthoven
Copy link
Author

i am using jenkins server sir, if i am using neutron 15 then this error will not come right sir? please confirm Thanks

yeah, it will fix the glibc not found errors.

@Mikdadali
Copy link

okay sir thank you then using 15

@itsHanibee
Copy link

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

@beakthoven
Copy link
Author

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

Sure, I will look into it... It would be helpful if you could provide some more details about the issue or error logs.

@itsHanibee
Copy link

itsHanibee commented May 25, 2023

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

Sure, I will look into it... It would be helpful if you could provide some more details about the issue or error logs.

mhm of course!
i have this script running on a ci right now, I'll send you the output logs.

in the meantime, the link you use to download patchelf from the aur:
https://archlinux.org/packages/community/x86_64/patchelf/download/

that returns a 404, i found out something cool. turns out that patchelf now lives at:
https://archlinux.org/packages/extra/x86_64/patchelf/download/

edit:
logs! https://github.com/itsHanibee/kernel_xiaomi_chime/suites/13138951417/logs?attempt=1

@beakthoven
Copy link
Author

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

Sure, I will look into it... It would be helpful if you could provide some more details about the issue or error logs.

mhm of course! i have this script running on a ci right now, I'll send you the output logs.

in the meantime, the link you use to download patchelf from the aur: https://archlinux.org/packages/community/x86_64/patchelf/download/

that returns a 404, i found out something cool. turns out that patchelf now lives at: https://archlinux.org/packages/extra/x86_64/patchelf/download/

edit: logs! https://github.com/itsHanibee/kernel_xiaomi_chime/suites/13138951417/logs?attempt=1

Thanks for the quick response, It seems like the change in link path has caused the script to break. I will try to update the link ASAP.

Btw, I have noticed that you use antman to sync the toolchain, I would recommend to use it to patch toolchain for glibc' issue as well, it's the same but simpler script integrated into antman, Introduced in this commit. You can patch toolchain for glibc issue by running ./antman --patch=glibc .

Note that the link in antman must also be updated, So currently it would be broken as well.

@itsHanibee
Copy link

itsHanibee commented May 26, 2023

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

Sure, I will look into it... It would be helpful if you could provide some more details about the issue or error logs.

mhm of course! i have this script running on a ci right now, I'll send you the output logs.
in the meantime, the link you use to download patchelf from the aur: https://archlinux.org/packages/community/x86_64/patchelf/download/
that returns a 404, i found out something cool. turns out that patchelf now lives at: https://archlinux.org/packages/extra/x86_64/patchelf/download/
edit: logs! https://github.com/itsHanibee/kernel_xiaomi_chime/suites/13138951417/logs?attempt=1

Thanks for the quick response, It seems like the change in link path has caused the script to break. I will try to update the link ASAP.

Btw, I have noticed that you use antman to sync the toolchain, I would recommend to use it to patch toolchain for glibc' issue as well, it's the same but simpler script integrated into antman, Introduced in this commit. You can patch toolchain for glibc issue by running ./antman --patch=glibc .

Note that the link in antman must also be updated, So currently it would be broken as well.

oooo that actually sounds super cool, i didn't know that! will definitely use next time. also if you haven't fixed it yet can i do a quick pr on antman? it'll be a quick oss contribution and it seems like it's pretty simple to do!

i forked this script in the meantime and i just updated the link and it works perfectly fine so that's all there is to change I'm pretty sure. :)

EDIT!
you pull patchelf from nixos and the package seems to exist and everything looks like it'll work fine so there's nothing to fix! the aur packages are fine too ๐Ÿ˜„. good morning and have a great day!

@beakthoven
Copy link
Author

the script no longer works for some reason, it might be because arch did some housekeeping on their repos but i have no clue honestly. i use the script alot, can you please look at it again that would be very helpful.

Sure, I will look into it... It would be helpful if you could provide some more details about the issue or error logs.

mhm of course! i have this script running on a ci right now, I'll send you the output logs.
in the meantime, the link you use to download patchelf from the aur: https://archlinux.org/packages/community/x86_64/patchelf/download/
that returns a 404, i found out something cool. turns out that patchelf now lives at: https://archlinux.org/packages/extra/x86_64/patchelf/download/
edit: logs! https://github.com/itsHanibee/kernel_xiaomi_chime/suites/13138951417/logs?attempt=1

Thanks for the quick response, It seems like the change in link path has caused the script to break. I will try to update the link ASAP.
Btw, I have noticed that you use antman to sync the toolchain, I would recommend to use it to patch toolchain for glibc' issue as well, it's the same but simpler script integrated into antman, Introduced in this commit. You can patch toolchain for glibc issue by running ./antman --patch=glibc .
Note that the link in antman must also be updated, So currently it would be broken as well.

oooo that actually sounds super cool, i didn't know that! will definitely use next time. also if you haven't fixed it yet can i do a quick pr on antman? it'll be a quick oss contribution and it seems like it's pretty simple to do!

i forked this script in the meantime and i just updated the link and it works perfectly fine so that's all there is to change I'm pretty sure. :)

EDIT! you pull patchelf from nixos and the package seems to exist and everything looks like it'll work fine so there's nothing to fix! the aur packages are fine too ๐Ÿ˜„. good morning and have a great day!

Oh right I completely forgot that I use NixOS binaries in antman, I did it because NixOS release binaries are statically linked against musl libc, This allows the patchelf binary to be executed on platforms with very old glibc where ArchLinux's patchelf which is linked against newer glibc won't work.

So I think there is no changes required to be made in antman and users of this particular script can also safely migrate to antman.

@retrozenith
Copy link

retrozenith commented Mar 4, 2024

Hi. I am trying to build my Android Kernel (SM8350 Kernel https://github.com/glikched/android_kernel_samsung_sm8350). But it seems something needs to be also patched.

Info: WSL2 Ubuntu 22.04.4 LTS on Windows 10 x86_64 (5.15.133.1-microsoft-standard-WSL2)

Error:
ld.lld: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ld.lld)

@beakthoven
Copy link
Author

Hi. I am trying to build my Android Kernel (SM8350 Kernel https://github.com/glikched/android_kernel_samsung_sm8350). But it seems something needs to be also patched.

Info: WSL2 Ubuntu 22.04.4 LTS on Windows 10 x86_64 (5.15.133.1-microsoft-standard-WSL2)

Error: ld.lld: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by ld.lld)

This script's functionality has been moved to antman utility and since v2.4 update it can handle glibcxx patching along with glibc. Please migrate to antman utility for patching your toolchain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment