Skip to content

Commit 8c3f650

Browse files
committed
x86_64: add support for pie executables
1 parent 26b1dc8 commit 8c3f650

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+887
-639
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ set(ZIG_STAGE2_SOURCES
519519
src/Air/Legalize.zig
520520
src/Air/Liveness.zig
521521
src/Air/Liveness/Verify.zig
522+
src/Air/print.zig
522523
src/Air/types_resolved.zig
523524
src/Builtin.zig
524525
src/Compilation.zig
@@ -675,7 +676,6 @@ set(ZIG_STAGE2_SOURCES
675676
src/libs/mingw.zig
676677
src/libs/musl.zig
677678
src/mutable_value.zig
678-
src/print_air.zig
679679
src/print_env.zig
680680
src/print_targets.zig
681681
src/print_value.zig

lib/std/builtin.zig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub const StackTrace = struct {
6161

6262
/// This data structure is used by the Zig language code generation and
6363
/// therefore must be kept in sync with the compiler implementation.
64-
pub const GlobalLinkage = enum {
64+
pub const GlobalLinkage = enum(u2) {
6565
internal,
6666
strong,
6767
weak,
@@ -70,7 +70,7 @@ pub const GlobalLinkage = enum {
7070

7171
/// This data structure is used by the Zig language code generation and
7272
/// therefore must be kept in sync with the compiler implementation.
73-
pub const SymbolVisibility = enum {
73+
pub const SymbolVisibility = enum(u2) {
7474
default,
7575
hidden,
7676
protected,
@@ -1030,8 +1030,19 @@ pub const ExternOptions = struct {
10301030
name: []const u8,
10311031
library_name: ?[]const u8 = null,
10321032
linkage: GlobalLinkage = .strong,
1033+
visibility: SymbolVisibility = .default,
1034+
/// Setting this to `true` makes the `@extern` a runtime value.
10331035
is_thread_local: bool = false,
10341036
is_dll_import: bool = false,
1037+
relocation: Relocation = .any,
1038+
1039+
pub const Relocation = enum(u1) {
1040+
/// Any type of relocation is allowed.
1041+
any,
1042+
/// A program-counter-relative relocation is required.
1043+
/// Using this value makes the `@extern` a runtime value.
1044+
pcrel,
1045+
};
10351046
};
10361047

10371048
/// This data structure is used by the Zig language code generation and

lib/std/dynamic_library.zig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ const RDebug = extern struct {
8383
r_ldbase: usize,
8484
};
8585

86-
/// TODO make it possible to reference this same external symbol 2x so we don't need this
87-
/// helper function.
88-
pub fn get_DYNAMIC() ?[*]elf.Dyn {
89-
return @extern([*]elf.Dyn, .{ .name = "_DYNAMIC", .linkage = .weak });
86+
/// TODO fix comparisons of extern symbol pointers so we don't need this helper function.
87+
pub fn get_DYNAMIC() ?[*]const elf.Dyn {
88+
return @extern([*]const elf.Dyn, .{
89+
.name = "_DYNAMIC",
90+
.linkage = .weak,
91+
.visibility = .hidden,
92+
});
9093
}
9194

92-
pub fn linkmap_iterator(phdrs: []elf.Phdr) error{InvalidExe}!LinkMap.Iterator {
95+
pub fn linkmap_iterator(phdrs: []const elf.Phdr) error{InvalidExe}!LinkMap.Iterator {
9396
_ = phdrs;
9497
const _DYNAMIC = get_DYNAMIC() orelse {
9598
// No PT_DYNAMIC means this is either a statically-linked program or a

0 commit comments

Comments
 (0)