Code Monkey home page Code Monkey logo

Comments (7)

dvdfreitag avatar dvdfreitag commented on June 12, 2024 1

On further investigation, it seems this is the issue, from CMLFS/3-chroot/008-Adjust_Toolchain:

echo " --sysroot=/usr -Wl,-dynamic-linker /lib/ld-musl-$(uname -m).so.1" > \
     /llvmtools/bin/$(uname -m)-cmlfs-linux-musl.cfg

Here we are manually instructing clang to always insert -dynamic-linker, but clang can already build working dynamic libraries with the correct Interpreter:

# echo "int main(){}" > t.c
# clang -o t t.c --verbose -Wl,--verbose
"/llvmtools/bin/clang-12" -cc1 -triple x86_64-pc-linux-musl -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name t.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /llvmtools/lib/clang/12.0.0 -isysroot /llvmtools -internal-isystem /llvmtools/usr/local/include -internal-externc-isystem /llvmtools/include -internal-externc-isystem /llvmtools/usr/include -internal-isystem /llvmtools/lib/clang/12.0.0/include -fdebug-compilation-dir /sources/src/utmps-system/temp -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/t-edcaf0.o -x c t.c
# file t
t: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, not stripped

If I remove the -dynamic-linker section from the config file,

echo " --sysroot=/usr" > /llvmtools/bin/$(uname -m)-cmlfs-linux-musl.cfg

And rebuild:

# x86_64-cmlfs-linux-musl-clang -o t t.c --verbose -Wl,--verbose
Configuration file: /llvmtools/bin/x86_64-cmlfs-linux-musl.cfg
"/llvmtools/bin/clang-12" -cc1 -triple x86_64-cmlfs-linux-musl -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name t.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /llvmtools/lib/clang/12.0.0 -isysroot /usr -internal-isystem /usr/usr/local/include -internal-externc-isystem /usr/include -internal-externc-isystem /usr/usr/include -internal-isystem /llvmtools/lib/clang/12.0.0/include -fdebug-compilation-dir /sources/src/utmps-system/temp -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/t-9e1d1a.o -x c t.c
# file t
t: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, not stripped

Once this change has been made, with CC=x86_64-cmlfs-linux-musl-clang:

# file utmps-utmpd 
utmps-utmpd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
# ./utmps-utmpd 
utmps-utmpd: fatal: unable to get $IPCREMOTEEUID from environment

utmps succeeds to build, and works without Segmentation Fault

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

I created CMLFS/3-chroot/008-Adjust_Toolchain because the llvmtools toolchain produced binaries that looked for an interpreter in /llvmtools instead on the final system root.

LLVM docs don't seem to be much help when trying to build sandboxed toolchains.

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

I had trouble starting up a new build with LLVM-12.x and moved on to LLVM-15.0.5. Of course, there seems to be drastic changes in LLVM source from 12.x to 15.x which required me to rethink the method to cross compile clang.

After many painful days of failure, I got LLVM-15.0.5 to cross compile. By now, stage 1 clang [installed in llvmtools] links all binaries with -dynamic-linker /lib/ld-musl-$(uname -m).so.1 without a config file. So, stage 1 clang only needs to be re-configured to change sysroot from /llvmtools to /usr ... just as you have mentioned above

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

This has been addressed via commit 0bfc298

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

commit bc471a8 now recognizes this change

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

Issue still present.

Stage1 clang outputs compiled code that uses the dynamic linux loader in /llvmtools/lib. After the system libc [musl] is built, then stage1 clang needs to be reconfigured to produce compiled code that uses the dynamic linux loader in /lib

Either I add patchelf to llvmtools to manually patch shared binaries to use the dynamic linux loader in /lib [until the stage2 clang, the final system's compiler is built] OR .... compile stage1 clang twice, one per dynamic loader path.

from cmlfs.

dslm4515 avatar dslm4515 commented on June 12, 2024

Stage0 clang now builds the final system's default compiler which by default produces binaries that use the dynamic linker in /lib/ld-musl-$(uname m).so.1 as this change was done with commit 550cf2c

Now when utmps is built [in chroot], the final system's clang builds it with no cfg. Therefore, static binaries are not built with -dynamic-linker.

This change is present on the mussel-bootsrapped branch. Once I confirm this branch can indeed build a usable CMLFS system, I will merge it into master and CMLFS will then be built with mussel.

from cmlfs.

Related Issues (20)

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.