mirror of
https://github.com/ziglang/zig.git
synced 2024-11-14 16:13:24 +00:00
Compilation: Use the regular module mechanism for setting PIC on CRT objects.
addCCArgs() will then pass the appropriate flag to Clang.
This commit is contained in:
parent
39abcc303c
commit
4c70aea460
@ -6266,6 +6266,7 @@ pub fn build_crt_file(
|
||||
comp: *Compilation,
|
||||
root_name: []const u8,
|
||||
output_mode: std.builtin.OutputMode,
|
||||
pic: ?bool,
|
||||
misc_task_tag: MiscTask,
|
||||
prog_node: std.Progress.Node,
|
||||
/// These elements have to get mutated to add the owner module after it is
|
||||
@ -6318,7 +6319,8 @@ pub fn build_crt_file(
|
||||
.omit_frame_pointer = comp.root_mod.omit_frame_pointer,
|
||||
.valgrind = false,
|
||||
.unwind_tables = false,
|
||||
.pic = comp.root_mod.pic,
|
||||
// Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC.
|
||||
.pic = pic orelse comp.root_mod.pic,
|
||||
.optimize_mode = comp.compilerRtOptMode(),
|
||||
.structured_cfg = comp.root_mod.structured_cfg,
|
||||
},
|
||||
|
@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = comp.root_mod,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files);
|
||||
return comp.build_crt_file("crti", .Obj, null, .@"glibc crti.o", prog_node, &files);
|
||||
},
|
||||
.crtn_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files);
|
||||
return comp.build_crt_file("crtn", .Obj, null, .@"glibc crtn.o", prog_node, &files);
|
||||
},
|
||||
.scrt1_o => {
|
||||
const start_o: Compilation.CSourceFile = blk: {
|
||||
@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
};
|
||||
var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o };
|
||||
const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1";
|
||||
return comp.build_crt_file(basename, .Obj, .@"glibc Scrt1.o", prog_node, &files);
|
||||
return comp.build_crt_file(basename, .Obj, null, .@"glibc Scrt1.o", prog_node, &files);
|
||||
},
|
||||
.libc_nonshared_a => {
|
||||
const s = path.sep_str;
|
||||
@ -413,7 +413,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
files_index += 1;
|
||||
}
|
||||
const files = files_buf[0..files_index];
|
||||
return comp.build_crt_file("c_nonshared", .Lib, .@"glibc libc_nonshared.a", prog_node, files);
|
||||
return comp.build_crt_file("c_nonshared", .Lib, null, .@"glibc libc_nonshared.a", prog_node, files);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files);
|
||||
return comp.build_crt_file("crt2", .Obj, null, .@"mingw-w64 crt2.o", prog_node, &files);
|
||||
},
|
||||
|
||||
.dllcrt2_o => {
|
||||
@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files);
|
||||
return comp.build_crt_file("dllcrt2", .Obj, null, .@"mingw-w64 dllcrt2.o", prog_node, &files);
|
||||
},
|
||||
|
||||
.mingw32_lib => {
|
||||
@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
} else {
|
||||
@panic("unsupported arch");
|
||||
}
|
||||
return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
|
||||
return comp.build_crt_file("mingw32", .Lib, null, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
14
src/musl.zig
14
src/musl.zig
@ -39,7 +39,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files);
|
||||
return comp.build_crt_file("crti", .Obj, null, .@"musl crti.o", prog_node, &files);
|
||||
},
|
||||
.crtn_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -51,7 +51,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files);
|
||||
return comp.build_crt_file("crtn", .Obj, null, .@"musl crtn.o", prog_node, &files);
|
||||
},
|
||||
.crt1_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -69,13 +69,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files);
|
||||
return comp.build_crt_file("crt1", .Obj, null, .@"musl crt1.o", prog_node, &files);
|
||||
},
|
||||
.rcrt1_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
try addCcArgs(comp, arena, &args, false);
|
||||
try args.appendSlice(&[_][]const u8{
|
||||
"-fPIC",
|
||||
"-fno-stack-protector",
|
||||
"-DCRT",
|
||||
});
|
||||
@ -88,13 +87,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files);
|
||||
return comp.build_crt_file("rcrt1", .Obj, true, .@"musl rcrt1.o", prog_node, &files);
|
||||
},
|
||||
.scrt1_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
try addCcArgs(comp, arena, &args, false);
|
||||
try args.appendSlice(&[_][]const u8{
|
||||
"-fPIC",
|
||||
"-fno-stack-protector",
|
||||
"-DCRT",
|
||||
});
|
||||
@ -107,7 +105,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files);
|
||||
return comp.build_crt_file("Scrt1", .Obj, true, .@"musl Scrt1.o", prog_node, &files);
|
||||
},
|
||||
.libc_a => {
|
||||
// When there is a src/<arch>/foo.* then it should substitute for src/foo.*
|
||||
@ -190,7 +188,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||
.owner = undefined,
|
||||
};
|
||||
}
|
||||
return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
|
||||
return comp.build_crt_file("c", .Lib, null, .@"musl libc.a", prog_node, c_source_files.items);
|
||||
},
|
||||
.libc_so => {
|
||||
const optimize_mode = comp.compilerRtOptMode();
|
||||
|
@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files);
|
||||
return comp.build_crt_file("crt1-reactor", .Obj, null, .@"wasi crt1-reactor.o", prog_node, &files);
|
||||
},
|
||||
.crt1_command_o => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
},
|
||||
};
|
||||
return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files);
|
||||
return comp.build_crt_file("crt1-command", .Obj, null, .@"wasi crt1-command.o", prog_node, &files);
|
||||
},
|
||||
.libc_a => {
|
||||
var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||
@ -150,7 +150,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
}
|
||||
}
|
||||
|
||||
try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items);
|
||||
try comp.build_crt_file("c", .Lib, null, .@"wasi libc.a", prog_node, libc_sources.items);
|
||||
},
|
||||
.libwasi_emulated_process_clocks_a => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
});
|
||||
}
|
||||
try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
|
||||
try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, null, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
|
||||
},
|
||||
.libwasi_emulated_getpid_a => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
});
|
||||
}
|
||||
try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
|
||||
try comp.build_crt_file("wasi-emulated-getpid", .Lib, null, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
|
||||
},
|
||||
.libwasi_emulated_mman_a => {
|
||||
var args = std.ArrayList([]const u8).init(arena);
|
||||
@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
.owner = undefined,
|
||||
});
|
||||
}
|
||||
try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
|
||||
try comp.build_crt_file("wasi-emulated-mman", .Lib, null, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
|
||||
},
|
||||
.libwasi_emulated_signal_a => {
|
||||
var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||
@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||
}
|
||||
}
|
||||
|
||||
try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);
|
||||
try comp.build_crt_file("wasi-emulated-signal", .Lib, null, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user