Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

folkertdev
Copy link
Contributor

Preparation for combining the C files. That is the biggest speedup, so I want to do that first to make later refactorings less painful.

@folkertdev folkertdev marked this pull request as ready for review July 10, 2025 22:28
@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

r? @sayantn

rustbot has assigned @sayantn.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@@ -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++"
Copy link
Contributor

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?

Copy link
Contributor Author

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):

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++?

Copy link
Contributor

@tgross35 tgross35 Jul 10, 2025

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@folkertdev folkertdev changed the title Streamline c compilation intrinsic-test: streamline c compilation Jul 11, 2025
@folkertdev folkertdev force-pushed the streamline-c-compilation branch from d2a815e to e8d5bc4 Compare July 12, 2025 11:20
Comment on lines +35 to +47
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"),
]);
Copy link
Contributor Author

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.

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

Successfully merging this pull request may close these issues.

4 participants