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

seL4test fails to compile with a x86_64-unknown-none-elf compiler #127

Closed
wucke13 opened this issue Nov 1, 2024 · 8 comments
Closed

seL4test fails to compile with a x86_64-unknown-none-elf compiler #127

wucke13 opened this issue Nov 1, 2024 · 8 comments

Comments

@wucke13
Copy link

wucke13 commented Nov 1, 2024

For historical reasons, the x86-*-elf compiler target treats a single forward slash (/) as beginning of comment. Now, the following test uses a single forward slash / (albeit in a pre-processor macro, this still triggers):

#define STACK_OFFSET_BYTES $(16 - (CONFIG_WORD_SIZE / 8))

The simple hotfix is to use a x86_64-unknown-linux-* compiler, which does not exert this behavior (as communicated back '05 on the gnu mailing lists). An alternative is to pass the flag --divide passed to x86_64-unknown-none-elf-as, to disable this behavior and treat a / int he middle of a pre-processor line as a true division.

Now, for most practical reason using a x86_64-unknown-linux-gnu targeted gcc likely is fine. But, conceptually this is unclean, one really does not need the Linux headers etc. to compile seL4, and on all other target architectures (except for the armv7 eabi stuff) the -elf works fine (as it should be).

wucke13 added a commit to DLR-FT/seL4-nix-utils that referenced this issue Nov 1, 2024
@wucke13 wucke13 changed the title seL4test fails to compile with a naked x86_64-unknown-none-elf compiler seL4test fails to compile with a x86_64-unknown-none-elf compiler Nov 1, 2024
@Indanz
Copy link
Contributor

Indanz commented Nov 1, 2024

That line was introduced by commit 5c3be68.

Seems it might be fixed by adding the --divide command line option to AS.

Or we can rewrite the code to not trigger this. Does it trigger if you write CONFIG_WORD_SIZE/8?

@wucke13
Copy link
Author

wucke13 commented Nov 1, 2024

Or we can rewrite the code to not trigger this. Does it trigger if you write CONFIG_WORD_SIZE/8?

No, but then the test is semantically altered, because the compiler only sees CONFIG_WORD_SIZE (everything past the first / in a line is discarded/treated as comment)

Seems it might be fixed by adding the --divide command line option to AS.

I'm currently tinkering with that. An issues I found is, that the build scripts invokes x86_64-unknown-none-elf-gcc to generate alignment_asm.S.obj. So, if I pass the --divide to ASMFLAGS, it gets passed to x86_64-unknown-none-elf-gcc which does not understand that flag. Only x86_64-unknown-none-elf-as does recognize it.

Just in case, yes I do have the AS environment variable set to x86_64-unknown-none-elf-as, so that is not the reason why *-gcc is used instead of -as to assemble the asm to object code.

@wucke13
Copy link
Author

wucke13 commented Nov 1, 2024

So, in Nix I can use the NIX_CFLAGS_COMPILE environment variable to inject arbitrary flags to the compiler x86_64-unknown-none-elf-gcc. Using that, I can pass -Wa,--divide, which in term tells gcc to pass --divide to the assembler. With that, it works for me. So, emitting the -Wa,--divide as additional flag to the compiler via the CMake scripts might fix this.

wucke13 added a commit to DLR-FT/seL4-nix-utils that referenced this issue Nov 1, 2024
@Indanz
Copy link
Contributor

Indanz commented Nov 1, 2024

I don't think any of us can be bothered writing a special check to the CMake scripts to check specifically for this issue, but feel free to send a patch.

It seems reasonable to expect people to add toolchain specific flags to their build environment when they use an unsupported toolchain, so closing this issue for now.

To be clear, I agree that x86_64-unknown-none-elf-gcc should work and that it's unfortunate that there's a stupid issue like this. But AFAIK, officially only the Linux toolchains are supported, even for Arm.

@Indanz Indanz closed this as completed Nov 1, 2024
wucke13 added a commit to DLR-FT/seL4-nix-utils that referenced this issue Nov 1, 2024
@Smattr
Copy link

Smattr commented Nov 1, 2024

Alternatively, you could rewrite the expression to CONFIG_WORD_SIZE >> 3.

@wucke13
Copy link
Author

wucke13 commented Nov 3, 2024

@Indanz

But AFAIK, officially only the Linux toolchains are supported, even for Arm.

Where would I read more about this? I kept wondering what toolchains are officially blessed, and I heared chatter (maybe from @Ivan-Velickovic ?) that the -linux toolchains are purely used because of availability in Debian repos. Authoritative information on the matter (that goes beyond a "just apt-get install whatever arm toolchains current Debian ships") would be appreciated from me!

@Indanz
Copy link
Contributor

Indanz commented Nov 3, 2024

Not sure, I guess it was based on: https://docs.sel4.systems/projects/buildsystem/host-dependencies.html

I remember trying to use aarch64-unknown-none-elf-gcc and it didn't work for some reason. Non-Microkit based systems follow the SYSV ABI for ELF files, maybe that's where the -linux toolchain requirement comes from. But if you have it working for sel4test then it may have been something else.

@Indanz
Copy link
Contributor

Indanz commented Nov 3, 2024

To elaborate, I would consider what's tested by CI as "officially supported". Anything deviating from that may not work for whatever stupid reason, which can be fixed if people send patches of course.

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

3 participants