authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-02 11:18:52+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-03 09:29:33+01:00
log4c70aea460d0cf4a5c1f77ec662837680e272220
treef20b65234d2f7e949d18fdd9d4f54c39924c65f3
parent39abcc303c471c0180cdb0f5dce4303bbbe45362
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Compilation: Use the regular module mechanism for setting PIC on CRT objects.

addCCArgs() will then pass the appropriate flag to Clang.

5 files changed, 23 insertions(+), 23 deletions(-)

src/Compilation.zig+3-1
......@@ -6266,6 +6266,7 @@ pub fn build_crt_file(
62666266 comp: *Compilation,
62676267 root_name: []const u8,
62686268 output_mode: std.builtin.OutputMode,
6269 pic: ?bool,
62696270 misc_task_tag: MiscTask,
62706271 prog_node: std.Progress.Node,
62716272 /// These elements have to get mutated to add the owner module after it is
......@@ -6318,7 +6319,8 @@ pub fn build_crt_file(
63186319 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
63196320 .valgrind = false,
63206321 .unwind_tables = false,
6321 .pic = comp.root_mod.pic,
6322 // Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC.
6323 .pic = pic orelse comp.root_mod.pic,
63226324 .optimize_mode = comp.compilerRtOptMode(),
63236325 .structured_cfg = comp.root_mod.structured_cfg,
63246326 },
src/glibc.zig+4-4
......@@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
221221 .owner = comp.root_mod,
222222 },
223223 };
224 return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files);
224 return comp.build_crt_file("crti", .Obj, null, .@"glibc crti.o", prog_node, &files);
225225 },
226226 .crtn_o => {
227227 var args = std.ArrayList([]const u8).init(arena);
......@@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
242242 .owner = undefined,
243243 },
244244 };
245 return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files);
245 return comp.build_crt_file("crtn", .Obj, null, .@"glibc crtn.o", prog_node, &files);
246246 },
247247 .scrt1_o => {
248248 const start_o: Compilation.CSourceFile = blk: {
......@@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
295295 };
296296 var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o };
297297 const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1";
298 return comp.build_crt_file(basename, .Obj, .@"glibc Scrt1.o", prog_node, &files);
298 return comp.build_crt_file(basename, .Obj, null, .@"glibc Scrt1.o", prog_node, &files);
299299 },
300300 .libc_nonshared_a => {
301301 const s = path.sep_str;
......@@ -413,7 +413,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
413413 files_index += 1;
414414 }
415415 const files = files_buf[0..files_index];
416 return comp.build_crt_file("c_nonshared", .Lib, .@"glibc libc_nonshared.a", prog_node, files);
416 return comp.build_crt_file("c_nonshared", .Lib, null, .@"glibc libc_nonshared.a", prog_node, files);
417417 },
418418 }
419419}
src/mingw.zig+3-3
......@@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
4141 .owner = undefined,
4242 },
4343 };
44 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files);
44 return comp.build_crt_file("crt2", .Obj, null, .@"mingw-w64 crt2.o", prog_node, &files);
4545 },
4646
4747 .dllcrt2_o => {
......@@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
5656 .owner = undefined,
5757 },
5858 };
59 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files);
59 return comp.build_crt_file("dllcrt2", .Obj, null, .@"mingw-w64 dllcrt2.o", prog_node, &files);
6060 },
6161
6262 .mingw32_lib => {
......@@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
118118 } else {
119119 @panic("unsupported arch");
120120 }
121 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
121 return comp.build_crt_file("mingw32", .Lib, null, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);
122122 },
123123 }
124124}
src/musl.zig+6-8
......@@ -39,7 +39,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
3939 .owner = undefined,
4040 },
4141 };
42 return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files);
42 return comp.build_crt_file("crti", .Obj, null, .@"musl crti.o", prog_node, &files);
4343 },
4444 .crtn_o => {
4545 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
5151 .owner = undefined,
5252 },
5353 };
54 return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files);
54 return comp.build_crt_file("crtn", .Obj, null, .@"musl crtn.o", prog_node, &files);
5555 },
5656 .crt1_o => {
5757 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
6969 .owner = undefined,
7070 },
7171 };
72 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files);
72 return comp.build_crt_file("crt1", .Obj, null, .@"musl crt1.o", prog_node, &files);
7373 },
7474 .rcrt1_o => {
7575 var args = std.ArrayList([]const u8).init(arena);
7676 try addCcArgs(comp, arena, &args, false);
7777 try args.appendSlice(&[_][]const u8{
78 "-fPIC",
7978 "-fno-stack-protector",
8079 "-DCRT",
8180 });
......@@ -88,13 +87,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
8887 .owner = undefined,
8988 },
9089 };
91 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files);
90 return comp.build_crt_file("rcrt1", .Obj, true, .@"musl rcrt1.o", prog_node, &files);
9291 },
9392 .scrt1_o => {
9493 var args = std.ArrayList([]const u8).init(arena);
9594 try addCcArgs(comp, arena, &args, false);
9695 try args.appendSlice(&[_][]const u8{
97 "-fPIC",
9896 "-fno-stack-protector",
9997 "-DCRT",
10098 });
......@@ -107,7 +105,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
107105 .owner = undefined,
108106 },
109107 };
110 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files);
108 return comp.build_crt_file("Scrt1", .Obj, true, .@"musl Scrt1.o", prog_node, &files);
111109 },
112110 .libc_a => {
113111 // 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
190188 .owner = undefined,
191189 };
192190 }
193 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
191 return comp.build_crt_file("c", .Lib, null, .@"musl libc.a", prog_node, c_source_files.items);
194192 },
195193 .libc_so => {
196194 const optimize_mode = comp.compilerRtOptMode();
src/wasi_libc.zig+7-7
......@@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
8181 .owner = undefined,
8282 },
8383 };
84 return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files);
84 return comp.build_crt_file("crt1-reactor", .Obj, null, .@"wasi crt1-reactor.o", prog_node, &files);
8585 },
8686 .crt1_command_o => {
8787 var args = std.ArrayList([]const u8).init(arena);
......@@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
9696 .owner = undefined,
9797 },
9898 };
99 return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files);
99 return comp.build_crt_file("crt1-command", .Obj, null, .@"wasi crt1-command.o", prog_node, &files);
100100 },
101101 .libc_a => {
102102 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
150150 }
151151 }
152152
153 try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items);
153 try comp.build_crt_file("c", .Lib, null, .@"wasi libc.a", prog_node, libc_sources.items);
154154 },
155155 .libwasi_emulated_process_clocks_a => {
156156 var args = std.ArrayList([]const u8).init(arena);
......@@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
167167 .owner = undefined,
168168 });
169169 }
170 try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
170 try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, null, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);
171171 },
172172 .libwasi_emulated_getpid_a => {
173173 var args = std.ArrayList([]const u8).init(arena);
......@@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
184184 .owner = undefined,
185185 });
186186 }
187 try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
187 try comp.build_crt_file("wasi-emulated-getpid", .Lib, null, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);
188188 },
189189 .libwasi_emulated_mman_a => {
190190 var args = std.ArrayList([]const u8).init(arena);
......@@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
201201 .owner = undefined,
202202 });
203203 }
204 try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
204 try comp.build_crt_file("wasi-emulated-mman", .Lib, null, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);
205205 },
206206 .libwasi_emulated_signal_a => {
207207 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
238238 }
239239 }
240240
241 try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);
241 try comp.build_crt_file("wasi-emulated-signal", .Lib, null, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);
242242 },
243243 }
244244}