| ... | ... | @@ -54,7 +54,7 @@ pub const DynamicSection = struct { |
| 54 | 54 | if (elf_file.base.options.z_now) { |
| 55 | 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 | 58 | flags_1 |= elf.DF_1_PIE; |
| 59 | 59 | } |
| 60 | 60 | // if (elf_file.base.options.z_nodlopen) { |
| ... | ... | @@ -226,7 +226,7 @@ pub const ZigGotSection = struct { |
| 226 | 226 | flags: Flags = .{}, |
| 227 | 227 | |
| 228 | 228 | const Flags = packed struct { |
| 229 | | needs_rela: bool = false, // TODO in prep for PIC/PIE and base relocations |
| 229 | needs_rela: bool = false, |
| 230 | 230 | dirty: bool = false, |
| 231 | 231 | }; |
| 232 | 232 | |
| ... | ... | @@ -251,7 +251,7 @@ pub const ZigGotSection = struct { |
| 251 | 251 | entry.* = sym_index; |
| 252 | 252 | const symbol = elf_file.symbol(sym_index); |
| 253 | 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 | 255 | zig_got.flags.needs_rela = true; |
| 256 | 256 | } |
| 257 | 257 | if (symbol.extra(elf_file)) |extra| { |
| ... | ... | @@ -491,7 +491,7 @@ pub const GotSection = struct { |
| 491 | 491 | const symbol = elf_file.symbol(sym_index); |
| 492 | 492 | symbol.flags.has_got = true; |
| 493 | 493 | 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 | 496 | got.flags.needs_rela = true; |
| 497 | 497 | } |
| ... | ... | @@ -582,8 +582,11 @@ pub const GotSection = struct { |
| 582 | 582 | if (symbol.?.flags.import) break :blk 0; |
| 583 | 583 | if (symbol.?.isIFunc(elf_file)) |
| 584 | 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 | 588 | break :blk if (apply_relocs) value else 0; |
| 589 | } |
| 587 | 590 | break :blk value; |
| 588 | 591 | }; |
| 589 | 592 | try writeInt(value, elf_file, writer); |
| ... | ... | @@ -655,7 +658,9 @@ pub const GotSection = struct { |
| 655 | 658 | }); |
| 656 | 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 | 664 | elf_file.addRelaDynAssumeCapacity(.{ |
| 660 | 665 | .offset = offset, |
| 661 | 666 | .type = elf.R_X86_64_RELATIVE, |
| ... | ... | @@ -734,8 +739,9 @@ pub const GotSection = struct { |
| 734 | 739 | inline else => elf_file.symbol(entry.symbol_index), |
| 735 | 740 | }; |
| 736 | 741 | switch (entry.tag) { |
| 737 | | .got => if (symbol.?.flags.import or |
| 738 | | symbol.?.isIFunc(elf_file) or (elf_file.base.options.pic and !symbol.?.isAbs(elf_file))) |
| 742 | .got => if (symbol.?.flags.import or symbol.?.isIFunc(elf_file) or |
| 743 | ((elf_file.isDynLib() or (elf_file.isExe() and elf_file.base.options.pie)) and |
| 744 | !symbol.?.isAbs(elf_file))) |
| 739 | 745 | { |
| 740 | 746 | num += 1; |
| 741 | 747 | }, |