-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
-fno-PIC targeting glibc should be legal #17430
Comments
OK, I've tried the proposed fix as follows: diff --git a/src/Compilation.zig b/src/Compilation.zig
index 28b67ff7346..0afcd9f03f5 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1034,7 +1034,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const must_pic: bool = b: {
if (target_util.requiresPIC(options.target, link_libc))
break :b true;
- break :b link_mode == .Dynamic;
+ break :b link_mode == .Dynamic and options.output_mode == .Lib;
};
const pic = if (options.want_pic) |explicit| pic: {
if (!explicit) {
@@ -5162,8 +5162,12 @@ pub fn addCCArgs(
},
}
- if (target_util.supports_fpic(target) and comp.bin_file.options.pic) {
- try argv.append("-fPIC");
+ if (target_util.supports_fpic(target)) {
+ if (comp.bin_file.options.pic) {
+ try argv.append("-fPIC");
+ } else {
+ try argv.append("-fno-PIC");
+ }
}
if (comp.unwind_tables) {
diff --git a/src/target.zig b/src/target.zig
index c137166543d..125f48f81b6 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -192,10 +192,10 @@ pub fn requiresPIE(target: std.Target) bool {
/// This function returns whether non-pic code is completely invalid on the given target.
pub fn requiresPIC(target: std.Target, linking_libc: bool) bool {
+ _ = linking_libc;
return target.isAndroid() or
target.os.tag == .windows or target.os.tag == .uefi or
- osRequiresLibC(target) or
- (linking_libc and target.isGnuLibC());
+ osRequiresLibC(target);
}
/// This is not whether the target supports Position Independent Code, but whether the -fPIC However, LLD fails to link
From my brief investigation this looks like a reference to Also, linking the binary with
I suspect there might be a bug in LLD somewhere, but instead of trying to narrow it down at this stage, I will defer it until our linker is capable of linking |
Currently, about 3.72 MB of Bun's executable is
|
I tried making this change again and ran test-behavior
└─ run test behavior-mips64-linux.4.19...6.10.3-gnuabi64.2.28-mips64-Debug-libc failure
qemu: uncaught target signal 10 (Bus error) - core dumped
error: the following command terminated with signal 7 (expected exited with code 0):
qemu-mips64 -L /opt/glibc/mips64-linux-gnuabi64 /home/alexrp/Source/zig/.zig-cache/o/15419225d1b4b615da9501b12d9a2344/test --seed=0x198ce05d --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=-
test-behavior
└─ run test behavior-mips64el-linux.4.19...6.10.3-gnuabi64.2.28-mips64-Debug-libc failure
qemu: uncaught target signal 10 (Bus error) - core dumped
error: the following command terminated with signal 7 (expected exited with code 0):
qemu-mips64el -L /opt/glibc/mips64el-linux-gnuabi64 /home/alexrp/Source/zig/.zig-cache/o/639bc2d91704d7f777acf4faff33380a/test --seed=0x198ce05d --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=-
test-behavior
└─ run test behavior-x86-linux.4.19...6.10.3-gnu.2.28-pentium4-Debug-libc failure
Arithmetic exception at address 0x2821a6
error: while executing test 'behavior.cast.test.@intFromFloat', the following command terminated with signal 11 (expected exited with code 0):
/home/alexrp/Source/zig/.zig-cache/o/5c98e94b27e524e8ccfff67b523bef97/test --seed=0x198ce05d --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=-
test-behavior
└─ run test behavior-arm-linux.4.19...6.10.3-gnueabihf.2.28-baseline-Debug-libc failure
Segmentation fault at address 0x8
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
error: while executing test 'behavior.usingnamespace.import_segregation.test.no clobbering happened', the following command terminated with signal 11 (expected exited with code 0):
qemu-arm -L /opt/glibc/arm-linux-gnueabihf /home/alexrp/Source/zig/.zig-cache/o/901cd9c1c937bc635e562270c3ed6f82/test --seed=0x198ce05d --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=-
test-behavior
└─ run test behavior-arm-linux.4.19...6.10.3-gnueabi.2.28-baseline-Debug-libc failure
Segmentation fault at address 0x8
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
error: while executing test 'behavior.usingnamespace.import_segregation.test.no clobbering happened', the following command terminated with signal 11 (expected exited with code 0):
qemu-arm -L /opt/glibc/arm-linux-gnueabi /home/alexrp/Source/zig/.zig-cache/o/02380e931e0244baf80cd3bc91b80682/test --seed=0x198ce05d --cache-dir=/home/alexrp/Source/zig/.zig-cache --listen=- (All other targets work.) All of the crashes happen in |
|
Zig Version
0.12.0-dev.832+d5c19ecd5
Steps to Reproduce and Observed Behavior
This is currently illegal:
but is actually a valid compilation combo.
Expected Behavior
Compiles successfully.
The text was updated successfully, but these errors were encountered: