authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-20 22:33:44+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-20 22:33:44+02:00
log6dc45e7d3186f81b1329c71b6380ff3ddd5dec41
tree4cee00278b17b4c5bb1079042c9acf54b2de2ce6
parent7de893c085c94934b2923a9659c9cf70b70d71b2
parentb8ff989fa0863984604591bfe1c54ddbf4e59806
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17621 from ziglang/elf-pic-pie

elf: actually check for dynamic executables

4 files changed, 95 insertions(+), 11 deletions(-)

src/link/Elf.zig+4-2
...@@ -2956,7 +2956,7 @@ fn writeHeader(self: *Elf) !void {...@@ -2956,7 +2956,7 @@ fn writeHeader(self: *Elf) !void {
2956 assert(index == 16);2956 assert(index == 16);
29572957
2958 const elf_type: elf.ET = switch (self.base.options.effectiveOutputMode()) {2958 const elf_type: elf.ET = switch (self.base.options.effectiveOutputMode()) {
2959 .Exe => if (self.base.options.pic) .DYN else .EXEC,2959 .Exe => if (self.base.options.pie) .DYN else .EXEC,
2960 .Obj => .REL,2960 .Obj => .REL,
2961 .Lib => switch (self.base.options.link_mode) {2961 .Lib => switch (self.base.options.link_mode) {
2962 .Static => @as(elf.ET, .REL),2962 .Static => @as(elf.ET, .REL),
...@@ -4874,6 +4874,7 @@ fn allocateSpecialPhdrs(self: *Elf) void {...@@ -4874,6 +4874,7 @@ fn allocateSpecialPhdrs(self: *Elf) void {
4874 phdr.p_align = shdr.sh_addralign;4874 phdr.p_align = shdr.sh_addralign;
4875 phdr.p_offset = shdr.sh_offset;4875 phdr.p_offset = shdr.sh_offset;
4876 phdr.p_vaddr = shdr.sh_addr;4876 phdr.p_vaddr = shdr.sh_addr;
4877 phdr.p_paddr = shdr.sh_addr;
4877 phdr.p_filesz = shdr.sh_size;4878 phdr.p_filesz = shdr.sh_size;
4878 phdr.p_memsz = shdr.sh_size;4879 phdr.p_memsz = shdr.sh_size;
4879 }4880 }
...@@ -5586,7 +5587,8 @@ const CsuObjects = struct {...@@ -5586,7 +5587,8 @@ const CsuObjects = struct {
5586};5587};
55875588
5588pub fn calcImageBase(self: Elf) u64 {5589pub fn calcImageBase(self: Elf) u64 {
5589 if (self.base.options.pic) return 0; // TODO flag an error if PIC and image_base_override5590 if (self.isDynLib()) return 0;
5591 if (self.isExe() and self.base.options.pie) return 0;
5590 return self.base.options.image_base_override orelse switch (self.ptr_width) {5592 return self.base.options.image_base_override orelse switch (self.ptr_width) {
5591 .p32 => 0x1000,5593 .p32 => 0x1000,
5592 .p64 => 0x1000000,5594 .p64 => 0x1000000,
src/link/Elf/Atom.zig+1-1
...@@ -600,7 +600,7 @@ fn dynAbsRelocAction(symbol: *const Symbol, elf_file: *Elf) RelocAction {...@@ -600,7 +600,7 @@ fn dynAbsRelocAction(symbol: *const Symbol, elf_file: *Elf) RelocAction {
600}600}
601601
602fn outputType(elf_file: *Elf) u2 {602fn outputType(elf_file: *Elf) u2 {
603 return switch (elf_file.base.options.output_mode) {603 return switch (elf_file.base.options.effectiveOutputMode()) {
604 .Obj => unreachable,604 .Obj => unreachable,
605 .Lib => 0,605 .Lib => 0,
606 .Exe => if (elf_file.base.options.pie) 1 else 2,606 .Exe => if (elf_file.base.options.pie) 1 else 2,
src/link/Elf/synthetic_sections.zig+14-8
...@@ -54,7 +54,7 @@ pub const DynamicSection = struct {...@@ -54,7 +54,7 @@ pub const DynamicSection = struct {
54 if (elf_file.base.options.z_now) {54 if (elf_file.base.options.z_now) {
55 flags_1 |= elf.DF_1_NOW;55 flags_1 |= elf.DF_1_NOW;
56 }56 }
57 if (elf_file.base.options.pie) {57 if (elf_file.isExe() and elf_file.base.options.pie) {
58 flags_1 |= elf.DF_1_PIE;58 flags_1 |= elf.DF_1_PIE;
59 }59 }
60 // if (elf_file.base.options.z_nodlopen) {60 // if (elf_file.base.options.z_nodlopen) {
...@@ -226,7 +226,7 @@ pub const ZigGotSection = struct {...@@ -226,7 +226,7 @@ pub const ZigGotSection = struct {
226 flags: Flags = .{},226 flags: Flags = .{},
227227
228 const Flags = packed struct {228 const Flags = packed struct {
229 needs_rela: bool = false, // TODO in prep for PIC/PIE and base relocations229 needs_rela: bool = false,
230 dirty: bool = false,230 dirty: bool = false,
231 };231 };
232232
...@@ -251,7 +251,7 @@ pub const ZigGotSection = struct {...@@ -251,7 +251,7 @@ pub const ZigGotSection = struct {
251 entry.* = sym_index;251 entry.* = sym_index;
252 const symbol = elf_file.symbol(sym_index);252 const symbol = elf_file.symbol(sym_index);
253 symbol.flags.has_zig_got = true;253 symbol.flags.has_zig_got = true;
254 if (elf_file.base.options.pic) {254 if (elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) {
255 zig_got.flags.needs_rela = true;255 zig_got.flags.needs_rela = true;
256 }256 }
257 if (symbol.extra(elf_file)) |extra| {257 if (symbol.extra(elf_file)) |extra| {
...@@ -491,7 +491,7 @@ pub const GotSection = struct {...@@ -491,7 +491,7 @@ pub const GotSection = struct {
491 const symbol = elf_file.symbol(sym_index);491 const symbol = elf_file.symbol(sym_index);
492 symbol.flags.has_got = true;492 symbol.flags.has_got = true;
493 if (symbol.flags.import or symbol.isIFunc(elf_file) or493 if (symbol.flags.import or symbol.isIFunc(elf_file) or
494 (elf_file.base.options.pic and !symbol.isAbs(elf_file)))494 ((elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) and !symbol.isAbs(elf_file)))
495 {495 {
496 got.flags.needs_rela = true;496 got.flags.needs_rela = true;
497 }497 }
...@@ -582,8 +582,11 @@ pub const GotSection = struct {...@@ -582,8 +582,11 @@ pub const GotSection = struct {
582 if (symbol.?.flags.import) break :blk 0;582 if (symbol.?.flags.import) break :blk 0;
583 if (symbol.?.isIFunc(elf_file))583 if (symbol.?.isIFunc(elf_file))
584 break :blk if (apply_relocs) value else 0;584 break :blk if (apply_relocs) value else 0;
585 if (elf_file.base.options.pic and !symbol.?.isAbs(elf_file))585 if ((elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) and
586 !symbol.?.isAbs(elf_file))
587 {
586 break :blk if (apply_relocs) value else 0;588 break :blk if (apply_relocs) value else 0;
589 }
587 break :blk value;590 break :blk value;
588 };591 };
589 try writeInt(value, elf_file, writer);592 try writeInt(value, elf_file, writer);
...@@ -655,7 +658,9 @@ pub const GotSection = struct {...@@ -655,7 +658,9 @@ pub const GotSection = struct {
655 });658 });
656 continue;659 continue;
657 }660 }
658 if (elf_file.base.options.pic and !symbol.?.isAbs(elf_file)) {661 if ((elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) and
662 !symbol.?.isAbs(elf_file))
663 {
659 elf_file.addRelaDynAssumeCapacity(.{664 elf_file.addRelaDynAssumeCapacity(.{
660 .offset = offset,665 .offset = offset,
661 .type = elf.R_X86_64_RELATIVE,666 .type = elf.R_X86_64_RELATIVE,
...@@ -734,8 +739,9 @@ pub const GotSection = struct {...@@ -734,8 +739,9 @@ pub const GotSection = struct {
734 inline else => elf_file.symbol(entry.symbol_index),739 inline else => elf_file.symbol(entry.symbol_index),
735 };740 };
736 switch (entry.tag) {741 switch (entry.tag) {
737 .got => if (symbol.?.flags.import or742 .got => if (symbol.?.flags.import or symbol.?.isIFunc(elf_file) or
738 symbol.?.isIFunc(elf_file) or (elf_file.base.options.pic and !symbol.?.isAbs(elf_file)))743 ((elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) and
744 !symbol.?.isAbs(elf_file)))
739 {745 {
740 num += 1;746 num += 1;
741 },747 },
test/link/elf.zig+76
...@@ -185,6 +185,8 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {...@@ -185,6 +185,8 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {
185 exe.addLibraryPath(libbaz.getEmittedBinDirectory());185 exe.addLibraryPath(libbaz.getEmittedBinDirectory());
186 exe.addRPath(libbaz.getEmittedBinDirectory());186 exe.addRPath(libbaz.getEmittedBinDirectory());
187 exe.linkLibC();187 exe.linkLibC();
188 // https://github.com/ziglang/zig/issues/17619
189 exe.pie = true;
188190
189 const run = addRunArtifact(exe);191 const run = addRunArtifact(exe);
190 run.expectStdOutEqual("42\n");192 run.expectStdOutEqual("42\n");
...@@ -211,6 +213,8 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {...@@ -211,6 +213,8 @@ fn testAsNeeded(b: *Build, opts: Options) *Step {
211 exe.addLibraryPath(libbaz.getEmittedBinDirectory());213 exe.addLibraryPath(libbaz.getEmittedBinDirectory());
212 exe.addRPath(libbaz.getEmittedBinDirectory());214 exe.addRPath(libbaz.getEmittedBinDirectory());
213 exe.linkLibC();215 exe.linkLibC();
216 // https://github.com/ziglang/zig/issues/17619
217 exe.pie = true;
214218
215 const run = addRunArtifact(exe);219 const run = addRunArtifact(exe);
216 run.expectStdOutEqual("42\n");220 run.expectStdOutEqual("42\n");
...@@ -396,6 +400,8 @@ fn testCopyrel(b: *Build, opts: Options) *Step {...@@ -396,6 +400,8 @@ fn testCopyrel(b: *Build, opts: Options) *Step {
396 , &.{});400 , &.{});
397 exe.linkLibrary(dso);401 exe.linkLibrary(dso);
398 exe.linkLibC();402 exe.linkLibC();
403 // https://github.com/ziglang/zig/issues/17619
404 exe.pie = true;
399405
400 const run = addRunArtifact(exe);406 const run = addRunArtifact(exe);
401 run.expectStdOutEqual("3 5\n");407 run.expectStdOutEqual("3 5\n");
...@@ -556,6 +562,8 @@ fn testDsoPlt(b: *Build, opts: Options) *Step {...@@ -556,6 +562,8 @@ fn testDsoPlt(b: *Build, opts: Options) *Step {
556 , &.{});562 , &.{});
557 exe.linkLibrary(dso);563 exe.linkLibrary(dso);
558 exe.linkLibC();564 exe.linkLibC();
565 // https://github.com/ziglang/zig/issues/17619
566 exe.pie = true;
559567
560 const run = addRunArtifact(exe);568 const run = addRunArtifact(exe);
561 run.expectStdOutEqual("Hello WORLD\n");569 run.expectStdOutEqual("Hello WORLD\n");
...@@ -591,6 +599,8 @@ fn testDsoUndef(b: *Build, opts: Options) *Step {...@@ -591,6 +599,8 @@ fn testDsoUndef(b: *Build, opts: Options) *Step {
591 \\}599 \\}
592 , &.{});600 , &.{});
593 exe.linkLibC();601 exe.linkLibC();
602 // https://github.com/ziglang/zig/issues/17619
603 exe.pie = true;
594604
595 const run = addRunArtifact(exe);605 const run = addRunArtifact(exe);
596 run.expectExitCode(0);606 run.expectExitCode(0);
...@@ -896,6 +906,8 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step {...@@ -896,6 +906,8 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step {
896 , &.{});906 , &.{});
897 exe.force_pic = true;907 exe.force_pic = true;
898 exe.linkLibC();908 exe.linkLibC();
909 // https://github.com/ziglang/zig/issues/17619
910 exe.pie = true;
899911
900 const run = addRunArtifact(exe);912 const run = addRunArtifact(exe);
901 run.expectExitCode(0);913 run.expectExitCode(0);
...@@ -1006,6 +1018,8 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step {...@@ -1006,6 +1018,8 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step {
1006 addCSourceBytes(exe, main_c, &.{});1018 addCSourceBytes(exe, main_c, &.{});
1007 exe.linkLibC();1019 exe.linkLibC();
1008 exe.link_z_lazy = true;1020 exe.link_z_lazy = true;
1021 // https://github.com/ziglang/zig/issues/17619
1022 exe.pie = true;
10091023
1010 const run = addRunArtifact(exe);1024 const run = addRunArtifact(exe);
1011 run.expectStdOutEqual("Hello world\n");1025 run.expectStdOutEqual("Hello world\n");
...@@ -1015,6 +1029,8 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step {...@@ -1015,6 +1029,8 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step {
1015 const exe = addExecutable(b, "other", opts);1029 const exe = addExecutable(b, "other", opts);
1016 addCSourceBytes(exe, main_c, &.{});1030 addCSourceBytes(exe, main_c, &.{});
1017 exe.linkLibC();1031 exe.linkLibC();
1032 // https://github.com/ziglang/zig/issues/17619
1033 exe.pie = true;
10181034
1019 const run = addRunArtifact(exe);1035 const run = addRunArtifact(exe);
1020 run.expectStdOutEqual("Hello world\n");1036 run.expectStdOutEqual("Hello world\n");
...@@ -1078,6 +1094,8 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step {...@@ -1078,6 +1094,8 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step {
1078 , &.{});1094 , &.{});
1079 exe.force_pic = true;1095 exe.force_pic = true;
1080 exe.linkLibC();1096 exe.linkLibC();
1097 // https://github.com/ziglang/zig/issues/17619
1098 exe.pie = true;
10811099
1082 const run = addRunArtifact(exe);1100 const run = addRunArtifact(exe);
1083 run.expectStdOutEqual("3\n");1101 run.expectStdOutEqual("3\n");
...@@ -1107,6 +1125,8 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step {...@@ -1107,6 +1125,8 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step {
1107 , &.{"-fno-plt"});1125 , &.{"-fno-plt"});
1108 exe.force_pic = true;1126 exe.force_pic = true;
1109 exe.linkLibC();1127 exe.linkLibC();
1128 // https://github.com/ziglang/zig/issues/17619
1129 exe.pie = true;
11101130
1111 const run = addRunArtifact(exe);1131 const run = addRunArtifact(exe);
1112 run.expectStdOutEqual("Hello world\n");1132 run.expectStdOutEqual("Hello world\n");
...@@ -1413,6 +1433,8 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step {...@@ -1413,6 +1433,8 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step {
1413 , &.{});1433 , &.{});
1414 exe.linkLibrary(dso);1434 exe.linkLibrary(dso);
1415 exe.linkLibC();1435 exe.linkLibC();
1436 // https://github.com/ziglang/zig/issues/17619
1437 exe.pie = true;
14161438
1417 const run = addRunArtifact(exe);1439 const run = addRunArtifact(exe);
1418 run.expectStdOutEqual("Hello world");1440 run.expectStdOutEqual("Hello world");
...@@ -1447,6 +1469,8 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step {...@@ -1447,6 +1469,8 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step {
1447 , &.{});1469 , &.{});
1448 exe.link_function_sections = true;1470 exe.link_function_sections = true;
1449 exe.linkLibC();1471 exe.linkLibC();
1472 // https://github.com/ziglang/zig/issues/17619
1473 exe.pie = true;
14501474
1451 const check = exe.checkObject();1475 const check = exe.checkObject();
1452 check.checkInSymtab();1476 check.checkInSymtab();
...@@ -1475,6 +1499,8 @@ fn testLargeBss(b: *Build, opts: Options) *Step {...@@ -1475,6 +1499,8 @@ fn testLargeBss(b: *Build, opts: Options) *Step {
1475 \\}1499 \\}
1476 , &.{});1500 , &.{});
1477 exe.linkLibC();1501 exe.linkLibC();
1502 // https://github.com/ziglang/zig/issues/17619
1503 exe.pie = true;
14781504
1479 const run = addRunArtifact(exe);1505 const run = addRunArtifact(exe);
1480 run.expectExitCode(0);1506 run.expectExitCode(0);
...@@ -1698,6 +1724,8 @@ fn testPltGot(b: *Build, opts: Options) *Step {...@@ -1698,6 +1724,8 @@ fn testPltGot(b: *Build, opts: Options) *Step {
1698 exe.linkLibrary(dso);1724 exe.linkLibrary(dso);
1699 exe.force_pic = true;1725 exe.force_pic = true;
1700 exe.linkLibC();1726 exe.linkLibC();
1727 // https://github.com/ziglang/zig/issues/17619
1728 exe.pie = true;
17011729
1702 const run = addRunArtifact(exe);1730 const run = addRunArtifact(exe);
1703 run.expectStdOutEqual("Hello world\n");1731 run.expectStdOutEqual("Hello world\n");
...@@ -1912,6 +1940,8 @@ fn testTlsDso(b: *Build, opts: Options) *Step {...@@ -1912,6 +1940,8 @@ fn testTlsDso(b: *Build, opts: Options) *Step {
1912 , &.{});1940 , &.{});
1913 exe.linkLibrary(dso);1941 exe.linkLibrary(dso);
1914 exe.linkLibC();1942 exe.linkLibC();
1943 // https://github.com/ziglang/zig/issues/17619
1944 exe.pie = true;
19151945
1916 const run = addRunArtifact(exe);1946 const run = addRunArtifact(exe);
1917 run.expectStdOutEqual("5 3 5 3 5 3\n");1947 run.expectStdOutEqual("5 3 5 3 5 3\n");
...@@ -2061,6 +2091,8 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step {...@@ -2061,6 +2091,8 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step {
2061 exe.linkLibrary(a_so);2091 exe.linkLibrary(a_so);
2062 exe.linkLibrary(b_so);2092 exe.linkLibrary(b_so);
2063 exe.linkLibC();2093 exe.linkLibC();
2094 // https://github.com/ziglang/zig/issues/17619
2095 exe.pie = true;
20642096
2065 const run = addRunArtifact(exe);2097 const run = addRunArtifact(exe);
2066 run.expectStdOutEqual("1 2 3 4 5 6\n");2098 run.expectStdOutEqual("1 2 3 4 5 6\n");
...@@ -2074,6 +2106,8 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step {...@@ -2074,6 +2106,8 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step {
2074 exe.linkLibrary(b_so);2106 exe.linkLibrary(b_so);
2075 exe.linkLibC();2107 exe.linkLibC();
2076 // exe.link_relax = false; // TODO2108 // exe.link_relax = false; // TODO
2109 // https://github.com/ziglang/zig/issues/17619
2110 exe.pie = true;
20772111
2078 const run = addRunArtifact(exe);2112 const run = addRunArtifact(exe);
2079 run.expectStdOutEqual("1 2 3 4 5 6\n");2113 run.expectStdOutEqual("1 2 3 4 5 6\n");
...@@ -2117,6 +2151,8 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step {...@@ -2117,6 +2151,8 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step {
2117 exe.addObject(b_o);2151 exe.addObject(b_o);
2118 exe.linkLibrary(dso);2152 exe.linkLibrary(dso);
2119 exe.linkLibC();2153 exe.linkLibC();
2154 // https://github.com/ziglang/zig/issues/17619
2155 exe.pie = true;
21202156
2121 const run = addRunArtifact(exe);2157 const run = addRunArtifact(exe);
2122 run.expectStdOutEqual("1 2 3\n");2158 run.expectStdOutEqual("1 2 3\n");
...@@ -2132,6 +2168,8 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step {...@@ -2132,6 +2168,8 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step {
2132 exe.addObject(b_o);2168 exe.addObject(b_o);
2133 exe.linkLibrary(dso);2169 exe.linkLibrary(dso);
2134 exe.linkLibC();2170 exe.linkLibC();
2171 // https://github.com/ziglang/zig/issues/17619
2172 exe.pie = true;
21352173
2136 const run = addRunArtifact(exe);2174 const run = addRunArtifact(exe);
2137 run.expectStdOutEqual("1 2 3\n");2175 run.expectStdOutEqual("1 2 3\n");
...@@ -2211,6 +2249,8 @@ fn testTlsIe(b: *Build, opts: Options) *Step {...@@ -2211,6 +2249,8 @@ fn testTlsIe(b: *Build, opts: Options) *Step {
2211 exe.addObject(main_o);2249 exe.addObject(main_o);
2212 exe.linkLibrary(dso);2250 exe.linkLibrary(dso);
2213 exe.linkLibC();2251 exe.linkLibC();
2252 // https://github.com/ziglang/zig/issues/17619
2253 exe.pie = true;
22142254
2215 const run = addRunArtifact(exe);2255 const run = addRunArtifact(exe);
2216 run.expectStdOutEqual(exp_stdout);2256 run.expectStdOutEqual(exp_stdout);
...@@ -2223,6 +2263,8 @@ fn testTlsIe(b: *Build, opts: Options) *Step {...@@ -2223,6 +2263,8 @@ fn testTlsIe(b: *Build, opts: Options) *Step {
2223 exe.linkLibrary(dso);2263 exe.linkLibrary(dso);
2224 exe.linkLibC();2264 exe.linkLibC();
2225 // exe.link_relax = false; // TODO2265 // exe.link_relax = false; // TODO
2266 // https://github.com/ziglang/zig/issues/17619
2267 exe.pie = true;
22262268
2227 const run = addRunArtifact(exe);2269 const run = addRunArtifact(exe);
2228 run.expectStdOutEqual(exp_stdout);2270 run.expectStdOutEqual(exp_stdout);
...@@ -2270,6 +2312,8 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step {...@@ -2270,6 +2312,8 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step {
2270 exe.addObject(c_o);2312 exe.addObject(c_o);
2271 exe.linkLibrary(dso);2313 exe.linkLibrary(dso);
2272 exe.linkLibC();2314 exe.linkLibC();
2315 // https://github.com/ziglang/zig/issues/17619
2316 exe.pie = true;
22732317
2274 const run = addRunArtifact(exe);2318 const run = addRunArtifact(exe);
2275 run.expectStdOutEqual("42 1 2 3\n");2319 run.expectStdOutEqual("42 1 2 3\n");
...@@ -2282,6 +2326,8 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step {...@@ -2282,6 +2326,8 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step {
2282 exe.addObject(b_o);2326 exe.addObject(b_o);
2283 exe.addObject(c_o);2327 exe.addObject(c_o);
2284 exe.linkLibC();2328 exe.linkLibC();
2329 // https://github.com/ziglang/zig/issues/17619
2330 exe.pie = true;
22852331
2286 const run = addRunArtifact(exe);2332 const run = addRunArtifact(exe);
2287 run.expectStdOutEqual("42 1 2 3\n");2333 run.expectStdOutEqual("42 1 2 3\n");
...@@ -2315,6 +2361,8 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {...@@ -2315,6 +2361,8 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
2315 \\}2361 \\}
2316 , &.{});2362 , &.{});
2317 exe.linkLibC();2363 exe.linkLibC();
2364 // https://github.com/ziglang/zig/issues/17619
2365 exe.pie = true;
23182366
2319 const run = addRunArtifact(exe);2367 const run = addRunArtifact(exe);
2320 run.expectStdOutEqual("3 0 5 0 0 0\n");2368 run.expectStdOutEqual("3 0 5 0 0 0\n");
...@@ -2337,6 +2385,8 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step {...@@ -2337,6 +2385,8 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step {
2337 , &.{});2385 , &.{});
2338 exe.force_pic = true;2386 exe.force_pic = true;
2339 exe.linkLibC();2387 exe.linkLibC();
2388 // https://github.com/ziglang/zig/issues/17619
2389 exe.pie = true;
23402390
2341 const run = addRunArtifact(exe);2391 const run = addRunArtifact(exe);
2342 run.expectStdOutEqual("1 2 3 0 5\n");2392 run.expectStdOutEqual("1 2 3 0 5\n");
...@@ -2375,6 +2425,8 @@ fn testTlsLd(b: *Build, opts: Options) *Step {...@@ -2375,6 +2425,8 @@ fn testTlsLd(b: *Build, opts: Options) *Step {
2375 exe.addObject(main_o);2425 exe.addObject(main_o);
2376 exe.addObject(a_o);2426 exe.addObject(a_o);
2377 exe.linkLibC();2427 exe.linkLibC();
2428 // https://github.com/ziglang/zig/issues/17619
2429 exe.pie = true;
23782430
2379 const run = addRunArtifact(exe);2431 const run = addRunArtifact(exe);
2380 run.expectStdOutEqual(exp_stdout);2432 run.expectStdOutEqual(exp_stdout);
...@@ -2387,6 +2439,8 @@ fn testTlsLd(b: *Build, opts: Options) *Step {...@@ -2387,6 +2439,8 @@ fn testTlsLd(b: *Build, opts: Options) *Step {
2387 exe.addObject(a_o);2439 exe.addObject(a_o);
2388 exe.linkLibC();2440 exe.linkLibC();
2389 // exe.link_relax = false; // TODO2441 // exe.link_relax = false; // TODO
2442 // https://github.com/ziglang/zig/issues/17619
2443 exe.pie = true;
23902444
2391 const run = addRunArtifact(exe);2445 const run = addRunArtifact(exe);
2392 run.expectStdOutEqual(exp_stdout);2446 run.expectStdOutEqual(exp_stdout);
...@@ -2420,6 +2474,8 @@ fn testTlsLdDso(b: *Build, opts: Options) *Step {...@@ -2420,6 +2474,8 @@ fn testTlsLdDso(b: *Build, opts: Options) *Step {
2420 , &.{});2474 , &.{});
2421 exe.linkLibrary(dso);2475 exe.linkLibrary(dso);
2422 exe.linkLibC();2476 exe.linkLibC();
2477 // https://github.com/ziglang/zig/issues/17619
2478 exe.pie = true;
24232479
2424 const run = addRunArtifact(exe);2480 const run = addRunArtifact(exe);
2425 run.expectStdOutEqual("1 2\n");2481 run.expectStdOutEqual("1 2\n");
...@@ -2457,6 +2513,8 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step {...@@ -2457,6 +2513,8 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step {
2457 exe.addObject(a_o);2513 exe.addObject(a_o);
2458 exe.addObject(b_o);2514 exe.addObject(b_o);
2459 exe.linkLibC();2515 exe.linkLibC();
2516 // https://github.com/ziglang/zig/issues/17619
2517 exe.pie = true;
24602518
2461 const run = addRunArtifact(exe);2519 const run = addRunArtifact(exe);
2462 run.expectStdOutEqual("3 5 3 5\n");2520 run.expectStdOutEqual("3 5 3 5\n");
...@@ -2469,6 +2527,8 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step {...@@ -2469,6 +2527,8 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step {
2469 exe.addObject(b_o);2527 exe.addObject(b_o);
2470 exe.linkLibC();2528 exe.linkLibC();
2471 // exe.link_relax = false; // TODO2529 // exe.link_relax = false; // TODO
2530 // https://github.com/ziglang/zig/issues/17619
2531 exe.pie = true;
24722532
2473 const run = addRunArtifact(exe);2533 const run = addRunArtifact(exe);
2474 run.expectStdOutEqual("3 5 3 5\n");2534 run.expectStdOutEqual("3 5 3 5\n");
...@@ -2554,6 +2614,8 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step {...@@ -2554,6 +2614,8 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step {
2554 exe.addRPath(dso.getEmittedBinDirectory());2614 exe.addRPath(dso.getEmittedBinDirectory());
2555 exe.linkLibC();2615 exe.linkLibC();
2556 exe.force_pic = true;2616 exe.force_pic = true;
2617 // https://github.com/ziglang/zig/issues/17619
2618 exe.pie = true;
25572619
2558 const run = addRunArtifact(exe);2620 const run = addRunArtifact(exe);
2559 run.expectExitCode(0);2621 run.expectExitCode(0);
...@@ -2588,6 +2650,8 @@ fn testTlsPic(b: *Build, opts: Options) *Step {...@@ -2588,6 +2650,8 @@ fn testTlsPic(b: *Build, opts: Options) *Step {
2588 , &.{});2650 , &.{});
2589 exe.addObject(obj);2651 exe.addObject(obj);
2590 exe.linkLibC();2652 exe.linkLibC();
2653 // https://github.com/ziglang/zig/issues/17619
2654 exe.pie = true;
25912655
2592 const run = addRunArtifact(exe);2656 const run = addRunArtifact(exe);
2593 run.expectStdOutEqual("3 5 3 5\n");2657 run.expectStdOutEqual("3 5 3 5\n");
...@@ -2627,6 +2691,8 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step {...@@ -2627,6 +2691,8 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step {
2627 exe.addObject(b_o);2691 exe.addObject(b_o);
2628 exe.addObject(c_o);2692 exe.addObject(c_o);
2629 exe.linkLibC();2693 exe.linkLibC();
2694 // https://github.com/ziglang/zig/issues/17619
2695 exe.pie = true;
26302696
2631 const run = addRunArtifact(exe);2697 const run = addRunArtifact(exe);
2632 run.expectStdOutEqual("42\n");2698 run.expectStdOutEqual("42\n");
...@@ -2642,6 +2708,8 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step {...@@ -2642,6 +2708,8 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step {
2642 exe.addObject(c_o);2708 exe.addObject(c_o);
2643 exe.linkLibrary(dso);2709 exe.linkLibrary(dso);
2644 exe.linkLibC();2710 exe.linkLibC();
2711 // https://github.com/ziglang/zig/issues/17619
2712 exe.pie = true;
26452713
2646 const run = addRunArtifact(exe);2714 const run = addRunArtifact(exe);
2647 run.expectStdOutEqual("42\n");2715 run.expectStdOutEqual("42\n");
...@@ -2711,6 +2779,8 @@ fn testWeakExports(b: *Build, opts: Options) *Step {...@@ -2711,6 +2779,8 @@ fn testWeakExports(b: *Build, opts: Options) *Step {
2711 const exe = addExecutable(b, "main", opts);2779 const exe = addExecutable(b, "main", opts);
2712 exe.addObject(obj);2780 exe.addObject(obj);
2713 exe.linkLibC();2781 exe.linkLibC();
2782 // https://github.com/ziglang/zig/issues/17619
2783 exe.pie = true;
27142784
2715 const check = exe.checkObject();2785 const check = exe.checkObject();
2716 check.checkInDynamicSymtab();2786 check.checkInDynamicSymtab();
...@@ -2743,6 +2813,8 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step {...@@ -2743,6 +2813,8 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step {
2743 , &.{});2813 , &.{});
2744 exe.linkLibrary(dso);2814 exe.linkLibrary(dso);
2745 exe.linkLibC();2815 exe.linkLibC();
2816 // https://github.com/ziglang/zig/issues/17619
2817 exe.pie = true;
27462818
2747 const run = addRunArtifact(exe);2819 const run = addRunArtifact(exe);
2748 run.expectStdOutEqual("bar=-1\n");2820 run.expectStdOutEqual("bar=-1\n");
...@@ -2759,6 +2831,8 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step {...@@ -2759,6 +2831,8 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step {
2759 , &.{});2831 , &.{});
2760 exe.linkLibrary(dso);2832 exe.linkLibrary(dso);
2761 exe.linkLibC();2833 exe.linkLibC();
2834 // https://github.com/ziglang/zig/issues/17619
2835 exe.pie = true;
27622836
2763 const run = addRunArtifact(exe);2837 const run = addRunArtifact(exe);
2764 run.expectStdOutEqual("bar=5\n");2838 run.expectStdOutEqual("bar=5\n");
...@@ -2866,6 +2940,8 @@ fn testZText(b: *Build, opts: Options) *Step {...@@ -2866,6 +2940,8 @@ fn testZText(b: *Build, opts: Options) *Step {
2866 , &.{});2940 , &.{});
2867 exe.linkLibrary(dso);2941 exe.linkLibrary(dso);
2868 exe.linkLibC();2942 exe.linkLibC();
2943 // https://github.com/ziglang/zig/issues/17619
2944 exe.pie = true;
28692945
2870 const run = addRunArtifact(exe);2946 const run = addRunArtifact(exe);
2871 run.expectStdOutEqual("3\n");2947 run.expectStdOutEqual("3\n");