| author | |
| committer | |
| log | 479f259ea4799583f4062b2dffb7d9a289f7e18b |
| tree | e96bd2a15781dc517740b695b132974685d0f3a5 |
| parent | a1fb10b766bcf05bb8e40bf77fd538c5dbdede97 |
* always align the stack to 16. I saw an instance on x86_64 linux where
it was needed.
* detect at runtime if being interpreted by a dynamic loader and if so
avoid clobbering the fs register.2 files changed, 16 insertions(+), 6 deletions(-)
lib/std/dynamic_library.zig+7-1| ... | ... | @@ -59,8 +59,14 @@ const RDebug = extern struct { |
| 59 | 59 | r_ldbase: usize, |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | /// TODO make it possible to reference this same external symbol 2x so we don't need this | |
| 63 | /// helper function. | |
| 64 | pub fn get_DYNAMIC() ?[*]elf.Dyn { | |
| 65 | return @extern([*]elf.Dyn, .{ .name = "_DYNAMIC", .linkage = .Weak }); | |
| 66 | } | |
| 67 | ||
| 62 | 68 | pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator { |
| 63 | const _DYNAMIC = @extern([*]elf.Dyn, .{ .name = "_DYNAMIC", .linkage = .Weak }) orelse { | |
| 69 | const _DYNAMIC = get_DYNAMIC() orelse { | |
| 64 | 70 | // No PT_DYNAMIC means this is either a statically-linked program or a |
| 65 | 71 | // badly corrupted dynamically-linked one. |
| 66 | 72 | return LinkMap.Iterator{ .current = null }; |
lib/std/start.zig+9-5| ... | ... | @@ -187,9 +187,8 @@ fn wWinMainCRTStartup() callconv(std.os.windows.WINAPI) noreturn { |
| 187 | 187 | |
| 188 | 188 | // TODO https://github.com/ziglang/zig/issues/265 |
| 189 | 189 | fn posixCallMainAndExit() noreturn { |
| 190 | if (builtin.os.tag == .freebsd) { | |
| 191 | @setAlignStack(16); | |
| 192 | } | |
| 190 | @setAlignStack(16); | |
| 191 | ||
| 193 | 192 | const argc = argc_argv_ptr[0]; |
| 194 | 193 | const argv = @ptrCast([*][*:0]u8, argc_argv_ptr + 1); |
| 195 | 194 | |
| ... | ... | @@ -208,8 +207,13 @@ fn posixCallMainAndExit() noreturn { |
| 208 | 207 | @import("os/linux/start_pie.zig").apply_relocations(); |
| 209 | 208 | } |
| 210 | 209 | |
| 211 | // Initialize the TLS area | |
| 212 | std.os.linux.tls.initStaticTLS(); | |
| 210 | // Initialize the TLS area. We do a runtime check here to make sure | |
| 211 | // this code is truly being statically executed and not inside a dynamic | |
| 212 | // loader, otherwise this would clobber the thread ID register. | |
| 213 | const is_dynamic = @import("dynamic_library.zig").get_DYNAMIC() != null; | |
| 214 | if (!is_dynamic) { | |
| 215 | std.os.linux.tls.initStaticTLS(); | |
| 216 | } | |
| 213 | 217 | |
| 214 | 218 | // TODO This is disabled because what should we do when linking libc and this code |
| 215 | 219 | // does not execute? And also it's causing a test failure in stack traces in release modes. |