diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-14 14:40:54 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-14 14:40:54 -0500 |
| commit | 1e481dfef5a2241bfc5460214dbd0daffe5063bc (patch) | |
| tree | ddb96972a8c593556b9d567e1b66ef3042ca2d0d /src | |
| parent | a64989ee704255f61639c9714c5a38b4d6eb0a9e (diff) | |
| parent | 3ed074171848f8ecbd57f8f361b790edfea97731 (diff) | |
| download | zig-1e481dfef5a2241bfc5460214dbd0daffe5063bc.tar.gz zig-1e481dfef5a2241bfc5460214dbd0daffe5063bc.zip | |
Merge pull request #10587 from xxxbxxx/master
restore compatibility with glibc<=2.33 for global initializers
Diffstat (limited to 'src')
| -rw-r--r-- | src/glibc.zig | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/glibc.zig b/src/glibc.zig index 65ee88ed81..dee4e50e37 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -182,6 +182,10 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { defer arena_allocator.deinit(); const arena = arena_allocator.allocator(); + const target = comp.getTarget(); + const target_ver = target.os.version_range.linux.glibc; + const start_old_init_fini = target_ver.order(.{ .major = 2, .minor = 33 }) != .gt; + switch (crt_file) { .crti_o => { var args = std.ArrayList([]const u8).init(arena); @@ -242,8 +246,9 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { "-DASSEMBLER", "-Wa,--noexecstack", }); + const src_path = if (start_old_init_fini) "start-2.33.S" else "start.S"; break :blk .{ - .src_path = try start_asm_path(comp, arena, "start.S"), + .src_path = try start_asm_path(comp, arena, src_path), .extra_flags = args.items, }; }; @@ -269,7 +274,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { return comp.build_crt_file("Scrt1", .Obj, &[_]Compilation.CSourceFile{ start_o, abi_note_o }); }, .libc_nonshared_a => { - const target = comp.getTarget(); const s = path.sep_str; const linux_prefix = lib_libc_glibc ++ "sysdeps" ++ s ++ "unix" ++ s ++ "sysv" ++ s ++ "linux" ++ s; @@ -277,6 +281,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { const Dep = struct { path: []const u8, flavor: Flavor = .shared, + exclude: bool = false, }; const deps = [_]Dep{ .{ @@ -296,6 +301,10 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { .flavor = .nonshared, }, .{ .path = lib_libc_glibc ++ "csu" ++ s ++ "errno.c" }, + .{ + .path = lib_libc_glibc ++ "csu" ++ s ++ "elf-init-2.33.c", + .exclude = !start_old_init_fini, + }, .{ .path = linux_prefix ++ "stat.c" }, .{ .path = linux_prefix ++ "fstat.c" }, .{ .path = linux_prefix ++ "lstat.c" }, @@ -309,9 +318,12 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { .{ .path = linux_prefix ++ "stat_t64_cp.c" }, }; - var c_source_files: [deps.len]Compilation.CSourceFile = undefined; + var files_buf: [deps.len]Compilation.CSourceFile = undefined; + var files_index: usize = 0; + + for (deps) |dep| { + if (dep.exclude) continue; - for (deps) |dep, i| { var args = std.ArrayList([]const u8).init(arena); try args.appendSlice(&[_][]const u8{ "-std=gnu11", @@ -353,12 +365,14 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { shared_def, "-DTOP_NAMESPACE=glibc", }); - c_source_files[i] = .{ + files_buf[files_index] = .{ .src_path = try lib_path(comp, arena, dep.path), .extra_flags = args.items, }; + files_index += 1; } - return comp.build_crt_file("c_nonshared", .Lib, &c_source_files); + const files = files_buf[0..files_index]; + return comp.build_crt_file("c_nonshared", .Lib, files); }, } } |
