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 {
364364 link_emit_relocs: bool = false,
365365 linker_script: ?[]const u8 = null,
366366 version_script: ?[]const u8 = null,
367 override_soname: ?[]const u8 = null,
367 soname: ?[]const u8 = null,
368368 linker_gc_sections: ?bool = null,
369369 linker_allow_shlib_undefined: ?bool = null,
370370 linker_bind_global_refs_locally: ?bool = null,
......@@ -828,7 +828,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
828828 .emit_relocs = options.link_emit_relocs,
829829 .rdynamic = options.rdynamic,
830830 .extra_lld_args = options.lld_argv,
831 .override_soname = options.override_soname,
831 .soname = options.soname,
832832 .version = options.version,
833833 .libc_installation = libc_dirs.libc_installation,
834834 .pic = pic,
src/glibc.zig+2-2
......@@ -917,7 +917,7 @@ fn buildSharedLib(
917917 };
918918 const version: std.builtin.Version = .{ .major = lib.sover, .minor = 0, .patch = 0 };
919919 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;
921921 const map_file_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, all_map_basename });
922922 const c_source_files = [1]Compilation.CSourceFile{
923923 .{
......@@ -955,7 +955,7 @@ fn buildSharedLib(
955955 .clang_passthrough_mode = comp.clang_passthrough_mode,
956956 .version = version,
957957 .version_script = map_file_path,
958 .override_soname = override_soname,
958 .soname = soname,
959959 .c_source_files = &c_source_files,
960960 .is_compiler_rt_or_libc = true,
961961 });
src/link.zig+1-1
......@@ -88,7 +88,7 @@ pub const Options = struct {
8888 subsystem: ?std.Target.SubSystem,
8989 linker_script: ?[]const u8,
9090 version_script: ?[]const u8,
91 override_soname: ?[]const u8,
91 soname: ?[]const u8,
9292 llvm_cpu_features: ?[*:0]const u8,
9393 /// Extra args passed directly to LLD. Ignored when not linking with LLD.
9494 extra_lld_args: []const []const u8,
src/link/Elf.zig+2-2
......@@ -1314,7 +1314,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13141314 }
13151315 }
13161316 if (is_dyn_lib) {
1317 man.hash.addOptionalBytes(self.base.options.override_soname);
1317 man.hash.addOptionalBytes(self.base.options.soname);
13181318 man.hash.addOptional(self.base.options.version);
13191319 }
13201320 man.hash.addStringSet(self.base.options.system_libs);
......@@ -1512,7 +1512,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
15121512 }
15131513
15141514 if (is_dyn_lib) {
1515 if (self.base.options.override_soname) |soname| {
1515 if (self.base.options.soname) |soname| {
15161516 try argv.append("-soname");
15171517 try argv.append(soname);
15181518 }
src/main.zig+12-12
......@@ -467,7 +467,7 @@ fn buildOutputType(
467467 var linker_script: ?[]const u8 = null;
468468 var version_script: ?[]const u8 = null;
469469 var disable_c_depfile = false;
470 var override_soname: ?[]const u8 = null;
470 var soname: ?[]const u8 = null;
471471 var linker_gc_sections: ?bool = null;
472472 var linker_allow_shlib_undefined: ?bool = null;
473473 var linker_bind_global_refs_locally: ?bool = null;
......@@ -1108,33 +1108,33 @@ fn buildOutputType(
11081108 if (i >= linker_args.items.len) {
11091109 fatal("expected linker arg after '{}'", .{arg});
11101110 }
1111 const soname = linker_args.items[i];
1112 override_soname = soname;
1111 const name = linker_args.items[i];
1112 soname = name;
11131113 // Use it as --name.
11141114 // Example: libsoundio.so.2
11151115 var prefix: usize = 0;
1116 if (mem.startsWith(u8, soname, "lib")) {
1116 if (mem.startsWith(u8, name, "lib")) {
11171117 prefix = 3;
11181118 }
1119 var end: usize = soname.len;
1120 if (mem.endsWith(u8, soname, ".so")) {
1119 var end: usize = name.len;
1120 if (mem.endsWith(u8, name, ".so")) {
11211121 end -= 3;
11221122 } else {
11231123 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])) {
11251125 found_digit = true;
11261126 end -= 1;
11271127 }
1128 if (found_digit and end > 0 and soname[end - 1] == '.') {
1128 if (found_digit and end > 0 and name[end - 1] == '.') {
11291129 end -= 1;
11301130 } else {
1131 end = soname.len;
1131 end = name.len;
11321132 }
1133 if (mem.endsWith(u8, soname[prefix..end], ".so")) {
1133 if (mem.endsWith(u8, name[prefix..end], ".so")) {
11341134 end -= 3;
11351135 }
11361136 }
1137 provided_name = soname[prefix..end];
1137 provided_name = name[prefix..end];
11381138 } else if (mem.eql(u8, arg, "-rpath")) {
11391139 i += 1;
11401140 if (i >= linker_args.items.len) {
......@@ -1660,7 +1660,7 @@ fn buildOutputType(
16601660 .linker_script = linker_script,
16611661 .version_script = version_script,
16621662 .disable_c_depfile = disable_c_depfile,
1663 .override_soname = override_soname,
1663 .soname = soname,
16641664 .linker_gc_sections = linker_gc_sections,
16651665 .linker_allow_shlib_undefined = linker_allow_shlib_undefined,
16661666 .linker_bind_global_refs_locally = linker_bind_global_refs_locally,