diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-11-23 12:00:12 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-11-23 12:00:12 +0100 |
| commit | 560043dadfa8bf3a6c15d7f09bfbc60e48e0084c (patch) | |
| tree | 035eaee95973b7387dd56b4ef6226d5f6d983dbf /lib | |
| parent | c7170e4a5480581db5f30913eebd9ad4f7cd121e (diff) | |
| download | zig-560043dadfa8bf3a6c15d7f09bfbc60e48e0084c.tar.gz zig-560043dadfa8bf3a6c15d7f09bfbc60e48e0084c.zip | |
Fix logic for detecting _DYNAMIC symbol
Prevent spurious crashes for non-PIE executables.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/dynamic_library.zig | 18 | ||||
| -rw-r--r-- | lib/std/process.zig | 2 |
2 files changed, 5 insertions, 15 deletions
diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 0de4bed84d..6c99ee644b 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -59,24 +59,12 @@ const RDebug = extern struct { r_ldbase: usize, }; -// TODO: This should be weak (#1917) -extern var _DYNAMIC: [128]elf.Dyn; - -comptime { - if (std.Target.current.os.tag == .linux) { - asm ( - \\ .weak _DYNAMIC - \\ .hidden _DYNAMIC - ); - } -} - pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator { - if (@ptrToInt(&_DYNAMIC[0]) == 0) { + const _DYNAMIC = @extern([*]elf.Dyn, .{ .name = "_DYNAMIC", .linkage = .Weak }) orelse { // No PT_DYNAMIC means this is either a statically-linked program or a - // badly corrupted one + // badly corrupted dynamically-linked one. return LinkMap.Iterator{ .current = null }; - } + }; const link_map_ptr = init: { var i: usize = 0; diff --git a/lib/std/process.zig b/lib/std/process.zig index b083126b31..5fc262e8b0 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -686,6 +686,8 @@ pub fn getBaseAddress() usize { if (base != 0) { return base; } + // XXX: Wrong for PIE executables, it should look at the difference + // between _DYNAMIC and the PT_DYNAMIC phdr instead. const phdr = os.system.getauxval(std.elf.AT_PHDR); return phdr - @sizeOf(std.elf.Ehdr); }, |
