Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking fails on dev-2024-05 with: cannot find crtbegin.o #3597

Open
eliaspekkala opened this issue May 17, 2024 · 6 comments
Open

Linking fails on dev-2024-05 with: cannot find crtbegin.o #3597

eliaspekkala opened this issue May 17, 2024 · 6 comments

Comments

@eliaspekkala
Copy link

Problem

./build_odin.sh succeeds on dev-2024-04a and prints the demo.

./build_odin.sh fails on dev-2024-05 with the following output:

~/Documents/odin $ ./build_odin.sh 
+ /usr/lib/llvm17/bin/clang++ src/main.cpp src/libtommath.cpp -Wno-switch -Wno-macro-redefined -Wno-unused-value '-DODIN_VERSION_RAW="dev-2024-05"' '-DGIT_SHA="2250eb3e7"' '-std=c++14' -I/usr/lib/llvm17/include '-std=c++17' -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/lib/llvm17/lib -g -pthread -lm -lstdc++ -ldl /usr/lib/llvm17/lib/libLLVM-17.so '-Wl,-rpath=$ORIGIN' -o odin
+ set +x
/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Somewhere between dev-2024-04a and dev-2024-05 an issue was introduced, or have the build requirements changed?

System

OS: Alpine Linux edge, Linux 6.6.30-0-lts
Arch: x86_64
Libc: musl

Version

Odin: dev-2024-05:2250eb3e7
Backend: LLVM 17.0.6

@marcs-feh
Copy link

marcs-feh commented May 20, 2024

I also had the same issue on Alpine. Here's a workaround you can do:

odin build your_dir -reloc-mode:pic -build-mode:obj
clang -fPIE your_dir.o -o your_executable

I have no idea why it's trying to link -lgcc.

@doedre
Copy link

doedre commented May 21, 2024

git bisect pointed me to d1a1e8f646c5b959be638aa955856f686b11a4f3 as the first faulty commit. Updating to LLVM 18.1.6 did not resolve this issue. Don't see where it tries to link -lgcc either.

@Kelimion
Copy link
Member

I can't replicate it on Ubuntu 24.04.
For LLVM 18:

[10:18] jeroen@CALISTO:/mnt/w/Odin $ ./build_odin.sh
+ /usr/lib/llvm-18/bin/clang++ src/main.cpp src/libtommath.cpp -Wno-switch -Wno-macro-redefined -Wno-unused-value -DODIN_VERSION_RAW="dev-2024-05" -DGIT_SHA="856537f0c" -std=c++14 -I/usr/lib/llvm-18/include -std=c++17 -fno-exceptions -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/lib/llvm-18/lib -g -pthread -lm -lstdc++ -ldl /usr/lib/llvm-18/lib/libLLVM-18.so -Wl,-rpath=$ORIGIN -o odin
+ set +x

# the basics
Hellope, World! from /mnt/w/Odin/demo.
<snip>

LLVM 17 either:

jeroen@CALISTO:/mnt/w/Odin $ LLVM_CONFIG=llvm-config-17 ./build_odin.sh
+ /usr/lib/llvm-17/bin/clang++ src/main.cpp src/libtommath.cpp -Wno-switch -Wno-macro-redefined -Wno-unused-value -DODIN_VERSION_RAW="dev-2024-05" -DGIT_SHA="856537f0c" -std=c++14 -I/usr/lib/llvm-17/include -std=c++17 -fno-exceptions -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -L/usr/lib/llvm-17/lib -g -pthread -lm -lstdc++ -ldl /usr/lib/llvm-17/lib/libLLVM-17.so -Wl,-rpath=$ORIGIN -o odin
+ set +x

# the basics
Hellope, World! from /mnt/w/Odin/demo.

@doedre
Copy link

doedre commented May 21, 2024

It can be temporarily fixed by specifying your target triple here. On my setup it's x86_64-alpine-linux-musl, so it should look like this:

bc->link_flags = concatenate3_strings(permanent_allocator(),
  str_lit("-target "), str_lit("x86_64-alpine-linux-musl"), str_lit(" "));

Tried to compile ols with it, works fine. Can't really come up with a better solution yet, as I'm not very familiar with the codebase.

@eliaspekkala
Copy link
Author

Thanks. I can confirm that this temporary fix works.

@laytan Seeing as you have worked on this part of the codebase before, do you know how we could make a more permanent fix to this issue?

@laytan
Copy link
Sponsor Contributor

laytan commented May 24, 2024

From the temporary fix it seems like using the -gnu suffixed targets makes it link in gcc?

Maybe this line needs changing:

str_lit("x86_64-pc-linux-gnu"),

Something like x86_64-pc-linux-elf instead?

But these are just initial guesses, I will try to find some time to test/reproduce this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants