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

Fix MIPS PIC level and work around an LLVM bug for mips(el)-linux-gnueabi(hf) #21224

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

alexrp
Copy link
Member

@alexrp alexrp commented Aug 28, 2024

This makes zig build test-modules -fqemu --glibc-runtimes <...> -Dtest-slow-targets -Dtest-target-filter=mips-linux.4.19...6.10.3-gnueabi -Dtest-target-filter=mipsel-linux.4.19...6.10.3-gnueabi mostly work, save for an fchmodat test failure that I still need to investigate.

@The-King-of-Toasters
Copy link
Contributor

Can you share the fchmodat failure here (or in another issue)? I wrote that code so I can give my 2¢.

@alexrp
Copy link
Member Author

alexrp commented Aug 28, 2024

I don't recall the exact failure, but it was one of the regfile asserts here:

zig/lib/std/posix/test.zig

Lines 1273 to 1289 in 1a178d4

try posix.fchmodat(tmp.dir.fd, "regfile", 0o640, 0);
try expectMode(tmp.dir.fd, "regfile", 0o640);
try posix.fchmodat(tmp.dir.fd, "regfile", 0o600, posix.AT.SYMLINK_NOFOLLOW);
try expectMode(tmp.dir.fd, "regfile", 0o600);
try posix.fchmodat(tmp.dir.fd, "symlink", 0o640, 0);
try expectMode(tmp.dir.fd, "regfile", 0o640);
try expectMode(tmp.dir.fd, "symlink", sym_mode);
var test_link = true;
posix.fchmodat(tmp.dir.fd, "symlink", 0o600, posix.AT.SYMLINK_NOFOLLOW) catch |err| switch (err) {
error.OperationNotSupported => test_link = false,
else => |e| return e,
};
if (test_link)
try expectMode(tmp.dir.fd, "symlink", 0o600);
try expectMode(tmp.dir.fd, "regfile", 0o640);

alexrp added 2 commits August 28, 2024 06:18
For hysterical raisins, MIPS always uses 1, regardless of `-fpic` vs `-fPIC`.
@alexrp alexrp changed the title Fix PIC level and work around an LLVM bug for mips(el)-linux-gnueabi(hf) Fix MIPS PIC level and work around an LLVM bug for mips(el)-linux-gnueabi(hf) Aug 28, 2024
Comment on lines 55 to 62
pub const setModulePICLevel = ZigLLVMSetModulePICLevel;
extern fn ZigLLVMSetModulePICLevel(module: *Module) void;
extern fn ZigLLVMSetModulePICLevel(module: *Module, big: bool) void;

pub const setModulePIELevel = ZigLLVMSetModulePIELevel;
extern fn ZigLLVMSetModulePIELevel(module: *Module) void;
extern fn ZigLLVMSetModulePIELevel(module: *Module, large: bool) void;

pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel;
extern fn ZigLLVMSetModuleCodeModel(module: *Module, code_model: CodeModel) void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API usage should not exist, we already have the ability to modify the module freely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, similar to float ABI, you can't set a code model on a bitcode module. So for these, we're stuck with the API (or llc later).

PIC/PIE are just module flags though, so I can look into emitting the module flags on our side in a follow-up PR if that's ok.

Copy link
Member

@jacobly0 jacobly0 Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, similar to float ABI, you can't set a code model on a bitcode module.

Correct for float ABI, but not for code model:

!7 = !{i32 1, !"Code Model", i32 1}

Generally anything being set on llvm::Module is part of the module, anything just being passed to codegen is not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #21238 so this isn't forgotten.

@andrewrk andrewrk merged commit e4e91a1 into ziglang:master Aug 30, 2024
10 checks passed
@alexrp alexrp deleted the mips-gnu-fixes branch August 31, 2024 01:19
@alexrp
Copy link
Member Author

alexrp commented Sep 1, 2024

I don't recall the exact failure, but it was one of the regfile asserts here:

@The-King-of-Toasters

test-modules
└─ test-std
   └─ run test std-mips-linux.4.19...6.10.3-gnueabihf.2.28-mips32-Debug-libc 2706/2792 passed, 1 failed, 85 skipped
error: 'posix.test.test.fchmodat smoke test' failed: expected 416, found 488
/home/alexrp/Source/zig/lib/std/testing.zig:97:17: 0xcac51b in expectEqualInner__anon_40880 (test)
                return error.TestExpectedEqual;
                ^
/home/alexrp/Source/zig/lib/std/posix/test.zig:1250:5: 0x25e90e7 in expectMode (test)
    try expectEqual(mode, st.mode & 0b111_111_111);
    ^
/home/alexrp/Source/zig/lib/std/posix/test.zig:1274:5: 0x25e973b in test.fchmodat smoke test (test)
    try expectMode(tmp.dir.fd, "regfile", 0o640);
    ^
error: while executing test 'zig.system.darwin.macos.test.detect', the following test command failed:
qemu-mips -L /opt/glibc/mips-linux-gnueabihf /home/alexrp/Source/zig/.zig-cache/o/a5712f20e8c3b4c16897214a501633b6/test --seed=0x55598d5a --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=-

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