authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-19 15:27:17+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-27 15:42:39-07:00
log375bab8460517f5d5ee02c161dc65ff1694132d7
tree02e428a21540cb8184f80271ef21b3c0a08a440c
parent12efefeba5a8128e0a79b4b04fad0d538c382e47

stage2 elf: refactor override_soname to soname


5 files changed, 19 insertions(+), 19 deletions(-)

src/Compilation.zig+2-2
...@@ -364,7 +364,7 @@ pub const InitOptions = struct {...@@ -364,7 +364,7 @@ pub const InitOptions = struct {
364 link_emit_relocs: bool = false,364 link_emit_relocs: bool = false,
365 linker_script: ?[]const u8 = null,365 linker_script: ?[]const u8 = null,
366 version_script: ?[]const u8 = null,366 version_script: ?[]const u8 = null,
367 override_soname: ?[]const u8 = null,367 soname: ?[]const u8 = null,
368 linker_gc_sections: ?bool = null,368 linker_gc_sections: ?bool = null,
369 linker_allow_shlib_undefined: ?bool = null,369 linker_allow_shlib_undefined: ?bool = null,
370 linker_bind_global_refs_locally: ?bool = null,370 linker_bind_global_refs_locally: ?bool = null,
...@@ -828,7 +828,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -828,7 +828,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
828 .emit_relocs = options.link_emit_relocs,828 .emit_relocs = options.link_emit_relocs,
829 .rdynamic = options.rdynamic,829 .rdynamic = options.rdynamic,
830 .extra_lld_args = options.lld_argv,830 .extra_lld_args = options.lld_argv,
831 .override_soname = options.override_soname,831 .soname = options.soname,
832 .version = options.version,832 .version = options.version,
833 .libc_installation = libc_dirs.libc_installation,833 .libc_installation = libc_dirs.libc_installation,
834 .pic = pic,834 .pic = pic,
src/glibc.zig+2-2
...@@ -917,7 +917,7 @@ fn buildSharedLib(...@@ -917,7 +917,7 @@ fn buildSharedLib(
917 };917 };
918 const version: std.builtin.Version = .{ .major = lib.sover, .minor = 0, .patch = 0 };918 const version: std.builtin.Version = .{ .major = lib.sover, .minor = 0, .patch = 0 };
919 const ld_basename = path.basename(comp.getTarget().standardDynamicLinkerPath().get().?);919 const ld_basename = path.basename(comp.getTarget().standardDynamicLinkerPath().get().?);
920 const override_soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else null;920 const soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else null;
921 const map_file_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, all_map_basename });921 const map_file_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, all_map_basename });
922 const c_source_files = [1]Compilation.CSourceFile{922 const c_source_files = [1]Compilation.CSourceFile{
923 .{923 .{
...@@ -955,7 +955,7 @@ fn buildSharedLib(...@@ -955,7 +955,7 @@ fn buildSharedLib(
955 .clang_passthrough_mode = comp.clang_passthrough_mode,955 .clang_passthrough_mode = comp.clang_passthrough_mode,
956 .version = version,956 .version = version,
957 .version_script = map_file_path,957 .version_script = map_file_path,
958 .override_soname = override_soname,958 .soname = soname,
959 .c_source_files = &c_source_files,959 .c_source_files = &c_source_files,
960 .is_compiler_rt_or_libc = true,960 .is_compiler_rt_or_libc = true,
961 });961 });
src/link.zig+1-1
...@@ -88,7 +88,7 @@ pub const Options = struct {...@@ -88,7 +88,7 @@ pub const Options = struct {
88 subsystem: ?std.Target.SubSystem,88 subsystem: ?std.Target.SubSystem,
89 linker_script: ?[]const u8,89 linker_script: ?[]const u8,
90 version_script: ?[]const u8,90 version_script: ?[]const u8,
91 override_soname: ?[]const u8,91 soname: ?[]const u8,
92 llvm_cpu_features: ?[*:0]const u8,92 llvm_cpu_features: ?[*:0]const u8,
93 /// Extra args passed directly to LLD. Ignored when not linking with LLD.93 /// Extra args passed directly to LLD. Ignored when not linking with LLD.
94 extra_lld_args: []const []const u8,94 extra_lld_args: []const []const u8,
src/link/Elf.zig+2-2
...@@ -1314,7 +1314,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1314,7 +1314,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1314 }1314 }
1315 }1315 }
1316 if (is_dyn_lib) {1316 if (is_dyn_lib) {
1317 man.hash.addOptionalBytes(self.base.options.override_soname);1317 man.hash.addOptionalBytes(self.base.options.soname);
1318 man.hash.addOptional(self.base.options.version);1318 man.hash.addOptional(self.base.options.version);
1319 }1319 }
1320 man.hash.addStringSet(self.base.options.system_libs);1320 man.hash.addStringSet(self.base.options.system_libs);
...@@ -1512,7 +1512,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1512,7 +1512,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1512 }1512 }
15131513
1514 if (is_dyn_lib) {1514 if (is_dyn_lib) {
1515 if (self.base.options.override_soname) |soname| {1515 if (self.base.options.soname) |soname| {
1516 try argv.append("-soname");1516 try argv.append("-soname");
1517 try argv.append(soname);1517 try argv.append(soname);
1518 }1518 }
src/main.zig+12-12
...@@ -467,7 +467,7 @@ fn buildOutputType(...@@ -467,7 +467,7 @@ fn buildOutputType(
467 var linker_script: ?[]const u8 = null;467 var linker_script: ?[]const u8 = null;
468 var version_script: ?[]const u8 = null;468 var version_script: ?[]const u8 = null;
469 var disable_c_depfile = false;469 var disable_c_depfile = false;
470 var override_soname: ?[]const u8 = null;470 var soname: ?[]const u8 = null;
471 var linker_gc_sections: ?bool = null;471 var linker_gc_sections: ?bool = null;
472 var linker_allow_shlib_undefined: ?bool = null;472 var linker_allow_shlib_undefined: ?bool = null;
473 var linker_bind_global_refs_locally: ?bool = null;473 var linker_bind_global_refs_locally: ?bool = null;
...@@ -1108,33 +1108,33 @@ fn buildOutputType(...@@ -1108,33 +1108,33 @@ fn buildOutputType(
1108 if (i >= linker_args.items.len) {1108 if (i >= linker_args.items.len) {
1109 fatal("expected linker arg after '{}'", .{arg});1109 fatal("expected linker arg after '{}'", .{arg});
1110 }1110 }
1111 const soname = linker_args.items[i];1111 const name = linker_args.items[i];
1112 override_soname = soname;1112 soname = name;
1113 // Use it as --name.1113 // Use it as --name.
1114 // Example: libsoundio.so.21114 // Example: libsoundio.so.2
1115 var prefix: usize = 0;1115 var prefix: usize = 0;
1116 if (mem.startsWith(u8, soname, "lib")) {1116 if (mem.startsWith(u8, name, "lib")) {
1117 prefix = 3;1117 prefix = 3;
1118 }1118 }
1119 var end: usize = soname.len;1119 var end: usize = name.len;
1120 if (mem.endsWith(u8, soname, ".so")) {1120 if (mem.endsWith(u8, name, ".so")) {
1121 end -= 3;1121 end -= 3;
1122 } else {1122 } else {
1123 var found_digit = false;1123 var found_digit = false;
1124 while (end > 0 and std.ascii.isDigit(soname[end - 1])) {1124 while (end > 0 and std.ascii.isDigit(name[end - 1])) {
1125 found_digit = true;1125 found_digit = true;
1126 end -= 1;1126 end -= 1;
1127 }1127 }
1128 if (found_digit and end > 0 and soname[end - 1] == '.') {1128 if (found_digit and end > 0 and name[end - 1] == '.') {
1129 end -= 1;1129 end -= 1;
1130 } else {1130 } else {
1131 end = soname.len;1131 end = name.len;
1132 }1132 }
1133 if (mem.endsWith(u8, soname[prefix..end], ".so")) {1133 if (mem.endsWith(u8, name[prefix..end], ".so")) {
1134 end -= 3;1134 end -= 3;
1135 }1135 }
1136 }1136 }
1137 provided_name = soname[prefix..end];1137 provided_name = name[prefix..end];
1138 } else if (mem.eql(u8, arg, "-rpath")) {1138 } else if (mem.eql(u8, arg, "-rpath")) {
1139 i += 1;1139 i += 1;
1140 if (i >= linker_args.items.len) {1140 if (i >= linker_args.items.len) {
...@@ -1660,7 +1660,7 @@ fn buildOutputType(...@@ -1660,7 +1660,7 @@ fn buildOutputType(
1660 .linker_script = linker_script,1660 .linker_script = linker_script,
1661 .version_script = version_script,1661 .version_script = version_script,
1662 .disable_c_depfile = disable_c_depfile,1662 .disable_c_depfile = disable_c_depfile,
1663 .override_soname = override_soname,1663 .soname = soname,
1664 .linker_gc_sections = linker_gc_sections,1664 .linker_gc_sections = linker_gc_sections,
1665 .linker_allow_shlib_undefined = linker_allow_shlib_undefined,1665 .linker_allow_shlib_undefined = linker_allow_shlib_undefined,
1666 .linker_bind_global_refs_locally = linker_bind_global_refs_locally,1666 .linker_bind_global_refs_locally = linker_bind_global_refs_locally,