-
Notifications
You must be signed in to change notification settings - Fork 296
intrinsic-test
: streamline c compilation
#1861
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
base: master
Are you sure you want to change the base?
Conversation
@@ -24,7 +24,7 @@ RUN mkdir /toolchains && mv "./${TOOLCHAIN}" /toolchains | |||
ENV AARCH64_BE_TOOLCHAIN="/toolchains/${TOOLCHAIN}" | |||
ENV AARCH64_BE_LIBC="${AARCH64_BE_TOOLCHAIN}/aarch64_be-none-linux-gnu/libc" | |||
|
|||
ENV CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER="${AARCH64_BE_TOOLCHAIN}/bin/aarch64_be-none-linux-gnu-gcc" | |||
ENV CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER="${AARCH64_BE_TOOLCHAIN}/bin/aarch64_be-none-linux-gnu-g++" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gcc can still be used to link c++ object files right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I ran into some linker issues with it earlier, and this is the linker that is picked here (and fixed those linker issues, though maybe other fixes were possible):
stdarch/crates/intrinsic-test/src/arm/compile.rs
Lines 34 to 37 in af2aa76
command = command | |
.set_linker( | |
cxx_toolchain_dir.unwrap_or("").to_string() + "/bin/aarch64_be-none-linux-gnu-g++", | |
) |
So this solved a problem and seemed more consistent. Are there downsides to using g++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None that I know of, I was just thinking it would be a change without any effect. Interesting that it makes a difference
edit: Oh, if it needs to link the c++ libraries then that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but on the other hand it did work up to now (and, it might still, I just had trouble with it earlier). But I figured we may as well be consistent here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digging in a little further, this is the linker command that we execute. Apparently clang19++
cannot itself construct the final binary, so intrinsic-test-programs.cpp
is first compiled to an object file by clang19++
, then linked using this custom linker. With gcc
this fails:
[crates/intrinsic-test/src/common/compile_c.rs:209:17] &cmd = Command {
program: "/toolchains/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64_be-none-linux-gnu/bin/aarch64_be-none-linux-gnu-gcc",
args: [
"/toolchains/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64_be-none-linux-gnu/bin/aarch64_be-none-linux-gnu-gcc",
"mod_0.o",
"mod_1.o",
"mod_2.o",
"mod_3.o",
"mod_4.o",
"mod_5.o",
"mod_6.o",
"mod_7.o",
"mod_8.o",
"mod_9.o",
"mod_10.o",
"mod_11.o",
"mod_12.o",
"mod_13.o",
"mod_14.o",
"mod_15.o",
"intrinsic-test-programs.o",
"-o",
"intrinsic-test-programs",
],
cwd: Some(
"c_programs",
),
create_pidfd: false,
}
This gives errors like this
aarch64_be-none-linux-gnu/bin/ld: mod_0.o: in function run___crc32b()':
mod_0.cpp:(.text+0x1c): undefined reference to std::cout'
aarch64_be-none-linux-gnu/bin/ld: mod_0.cpp:(.text+0x2c): undefined reference to std::cout'
aarch64_be-none-linux-gnu/bin/ld: mod_0.cpp:(.text+0x5c): undefined reference to std::ctype<char>::_M_widen_init() const'
aarch64_be-none-linux-gnu/bin/ld: mod_0.cpp:(.text+0x7c): undefined reference to std::ostream::put(char)'
aarch64_be-none-linux-gnu/bin/ld: mod_0.cpp:(.text+0x80): undefined reference to std::ostream::flush()'
aarch64_be-none-linux-gnu/bin/ld: mod_0.cpp:(.text+0xa4): undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
So yeah, we're linking C++ now, and then using g++
seems like the best option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang19++
cannot itself construct the final binary
that seems weird!
intrinsic-test
: streamline c compilation
d2a815e
to
e8d5bc4
Compare
cpp_compiler.command_mut().args([ | ||
&format!("--sysroot={cxx_toolchain_dir}/aarch64_be-none-linux-gnu/libc"), | ||
"--include-directory", | ||
&format!("{cxx_toolchain_dir}/aarch64_be-none-linux-gnu/include/c++/14.2.1"), | ||
"--include-directory", | ||
&format!("{cxx_toolchain_dir}/aarch64_be-none-linux-gnu/include/c++/14.2.1/aarch64_be-none-linux-gnu"), | ||
"-L", | ||
&format!("{cxx_toolchain_dir}/lib/gcc/aarch64_be-none-linux-gnu/14.2.1"), | ||
"-L", | ||
&format!("{cxx_toolchain_dir}/aarch64_be-none-linux-gnu/libc/usr/lib"), | ||
"-B", | ||
&format!("{cxx_toolchain_dir}/lib/gcc/aarch64_be-none-linux-gnu/14.2.1"), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I got this to work, meaning we can drop the custom linker stuff. I've also reverted the linker change from gcc
to g++
for now, it might be needed later but we can change it then.
Preparation for combining the C files. That is the biggest speedup, so I want to do that first to make later refactorings less painful.