Repository navigation
Compiler bug #13976
Description
Activity
- addedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
on Dec 16, 2022 - addedbackend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.upstreamAn issue with a third party project that Zig uses.An issue with a third party project that Zig uses.
on Dec 16, 2022 I'd like to say this is not zig's bug, this is the intended behavior. The related concept is [code model][https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html]. In gcc, it's controlled by
-mcmodel=small|medium|large. The default model is small model, all code and data must live in 2GB. WhenNB_BITSis set to 28 or higher,hasheswill exceed 2GB. That's the problem.However, currently zig's support for code model is very limited, only supporting default and tiny. If zig adds support for medium and large code model, the code should run in proper code model.- removedupstreamAn issue with a third party project that Zig uses.An issue with a third party project that Zig uses.backend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.
on Dec 20, 2022 I'd like to say this is not zig's bug, this is the intended behavior. The related concept is [code model][https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html]. In gcc, it's controlled by
-mcmodel=small|medium|large. The default model is small model, all code and data must live in 2GB. WhenNB_BITSis set to 28 or higher,hasheswill exceed 2GB. That's the problem.It's still a bug in that there should be a compiler error before it reaches the linker.
However, currently zig's support for code model is very limited, only supporting default and tiny. If zig adds support for medium and large code model, the code should run in proper code model.
Medium and large are supported in addition to small and kernel.
-mcmodel=[default|tiny| Limit range of code and data virtual addresses small|kernel| medium|large]It's still a bug in that there should be a compiler error before it reaches the linker.
I agree with you. gcc and clang do nothing and just defer the error to linking. If zig could detect this then give a nicer message instead of a cryptic linking error, this is definitely an improvement. But I'm afraid that it's hard to solve perfectly. Thinking an extreme case, two object files each contains a 1GB array, it will only explode when they are linking together.
Medium and large are supported in addition to small and kernel.
You are right. I was just using
zig build-exe -h | grep mcmodel, so I didn't see the last two lines, Sorry.I agree with you. gcc and clang do nothing and just defer the error to linking. If zig could detect this then give a nicer message instead of a cryptic linking error, this is definitely an improvement. But I'm afraid that it's hard to solve perfectly. Thinking an extreme case, two object files each contains a 1GB array, it will only explode when they are linking together.
Sure but a lot of the times a compilation will only contain Zig code which is all in one compilation unit in which this should be possible to detect.
- addedenhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.error messageThis issue points out an error message that is unhelpful and should be improved.This issue points out an error message that is unhelpful and should be improved.
on Dec 20, 2022
Zig Version
0.11.0-dev.815+88b49ed00
Steps to Reproduce and Observed Behavior
In the following code, the program compiles and runs properly when NB_BITS is 27 or less, but the compilation fails if it is 28 with a relocation problem:
Expected Behavior
Correct compilation...