aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-10-14 09:04:08 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-10-16 19:33:06 +0200
commit17635e4f2ae78e358a7a997b161e64de71a01191 (patch)
treedc688f054c6a6c1ab7d7e96f3cfc1c3bb127e44e /src/link
parentb3d98a4b88514b1e8d2cc07ef05c218f50f5f5d8 (diff)
downloadzig-17635e4f2ae78e358a7a997b161e64de71a01191.tar.gz
zig-17635e4f2ae78e358a7a997b161e64de71a01191.zip
x86_64: add -fPIC support targeting ELF
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Elf.zig3
-rw-r--r--src/link/Elf/Atom.zig31
2 files changed, 17 insertions, 17 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index f89f303c6a..5659bfc858 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -6074,6 +6074,9 @@ const SystemLib = struct {
path: []const u8,
};
+pub const R_X86_64_ZIG_GOT32 = elf.R_X86_64_NUM + 1;
+pub const R_X86_64_ZIG_GOTPCREL = elf.R_X86_64_NUM + 2;
+
const std = @import("std");
const build_options = @import("build_options");
const builtin = @import("builtin");
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig
index fae96dec5e..b0d780c0c3 100644
--- a/src/link/Elf/Atom.zig
+++ b/src/link/Elf/Atom.zig
@@ -370,16 +370,6 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, code: ?[]const u8, undefs: anytype
try self.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
},
- // TODO I have temporarily repurposed those for handling .zig.got indirection
- // but we should probably claim unused custom values for incremental linking
- // that get rewritten to standard relocs when lowering to a relocatable object
- // file.
- elf.R_X86_64_GOT32,
- elf.R_X86_64_GOT64,
- => {
- assert(symbol.flags.has_zig_got);
- },
-
elf.R_X86_64_GOTPC32,
elf.R_X86_64_GOTPC64,
elf.R_X86_64_GOTPCREL,
@@ -461,6 +451,13 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, code: ?[]const u8, undefs: anytype
elf.R_X86_64_TLSDESC_CALL,
=> {},
+ // Zig custom relocations
+ Elf.R_X86_64_ZIG_GOT32,
+ Elf.R_X86_64_ZIG_GOTPCREL,
+ => {
+ assert(symbol.flags.has_zig_got);
+ },
+
else => try self.reportUnhandledRelocError(rel, elf_file),
}
}
@@ -813,13 +810,6 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
elf.R_X86_64_32 => try cwriter.writeIntLittle(u32, @as(u32, @truncate(@as(u64, @intCast(S + A))))),
elf.R_X86_64_32S => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A))),
- // TODO I have temporarily repurposed those for handling .zig.got indirection
- // but we should probably claim unused custom values for incremental linking
- // that get rewritten to standard relocs when lowering to a relocatable object
- // file.
- elf.R_X86_64_GOT32 => try cwriter.writeIntLittle(u32, @as(u32, @intCast(ZIG_GOT + A))),
- elf.R_X86_64_GOT64 => try cwriter.writeIntLittle(u64, @as(u64, @intCast(ZIG_GOT + A))),
-
elf.R_X86_64_TPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A - TP))),
elf.R_X86_64_TPOFF64 => try cwriter.writeIntLittle(i64, S + A - TP),
@@ -888,6 +878,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
}
},
+ // Zig custom relocations
+ Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeIntLittle(u32, @as(u32, @intCast(ZIG_GOT + A))),
+ Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeIntLittle(i32, @as(i32, @intCast(ZIG_GOT + A - P))),
+
else => {},
}
}
@@ -1136,6 +1130,9 @@ fn formatRelocType(
elf.R_X86_64_GOTPCRELX => "R_X86_64_GOTPCRELX",
elf.R_X86_64_REX_GOTPCRELX => "R_X86_64_REX_GOTPCRELX",
elf.R_X86_64_NUM => "R_X86_64_NUM",
+ // Zig custom relocations
+ Elf.R_X86_64_ZIG_GOT32 => "R_X86_64_ZIG_GOT32",
+ Elf.R_X86_64_ZIG_GOTPCREL => "R_X86_64_ZIG_GOTPCREL",
else => "R_X86_64_UNKNOWN",
};
try writer.print("{s}", .{str});