stage2 elf: refactor override_soname to soname

This commit is contained in:
Jakub Konka 2020-11-19 15:27:17 +01:00 committed by Andrew Kelley
parent 12efefeba5
commit 375bab8460
5 changed files with 19 additions and 19 deletions

View File

@ -364,7 +364,7 @@ pub const InitOptions = struct {
link_emit_relocs: bool = false,
linker_script: ?[]const u8 = null,
version_script: ?[]const u8 = null,
override_soname: ?[]const u8 = null,
soname: ?[]const u8 = null,
linker_gc_sections: ?bool = null,
linker_allow_shlib_undefined: ?bool = null,
linker_bind_global_refs_locally: ?bool = null,
@ -828,7 +828,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.emit_relocs = options.link_emit_relocs,
.rdynamic = options.rdynamic,
.extra_lld_args = options.lld_argv,
.override_soname = options.override_soname,
.soname = options.soname,
.version = options.version,
.libc_installation = libc_dirs.libc_installation,
.pic = pic,

View File

@ -917,7 +917,7 @@ fn buildSharedLib(
};
const version: std.builtin.Version = .{ .major = lib.sover, .minor = 0, .patch = 0 };
const ld_basename = path.basename(comp.getTarget().standardDynamicLinkerPath().get().?);
const override_soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else null;
const soname = if (mem.eql(u8, lib.name, "ld")) ld_basename else null;
const map_file_path = try path.join(arena, &[_][]const u8{ bin_directory.path.?, all_map_basename });
const c_source_files = [1]Compilation.CSourceFile{
.{
@ -955,7 +955,7 @@ fn buildSharedLib(
.clang_passthrough_mode = comp.clang_passthrough_mode,
.version = version,
.version_script = map_file_path,
.override_soname = override_soname,
.soname = soname,
.c_source_files = &c_source_files,
.is_compiler_rt_or_libc = true,
});

View File

@ -88,7 +88,7 @@ pub const Options = struct {
subsystem: ?std.Target.SubSystem,
linker_script: ?[]const u8,
version_script: ?[]const u8,
override_soname: ?[]const u8,
soname: ?[]const u8,
llvm_cpu_features: ?[*:0]const u8,
/// Extra args passed directly to LLD. Ignored when not linking with LLD.
extra_lld_args: []const []const u8,

View File

@ -1314,7 +1314,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
}
}
if (is_dyn_lib) {
man.hash.addOptionalBytes(self.base.options.override_soname);
man.hash.addOptionalBytes(self.base.options.soname);
man.hash.addOptional(self.base.options.version);
}
man.hash.addStringSet(self.base.options.system_libs);
@ -1512,7 +1512,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
}
if (is_dyn_lib) {
if (self.base.options.override_soname) |soname| {
if (self.base.options.soname) |soname| {
try argv.append("-soname");
try argv.append(soname);
}

View File

@ -467,7 +467,7 @@ fn buildOutputType(
var linker_script: ?[]const u8 = null;
var version_script: ?[]const u8 = null;
var disable_c_depfile = false;
var override_soname: ?[]const u8 = null;
var soname: ?[]const u8 = null;
var linker_gc_sections: ?bool = null;
var linker_allow_shlib_undefined: ?bool = null;
var linker_bind_global_refs_locally: ?bool = null;
@ -1108,33 +1108,33 @@ fn buildOutputType(
if (i >= linker_args.items.len) {
fatal("expected linker arg after '{}'", .{arg});
}
const soname = linker_args.items[i];
override_soname = soname;
const name = linker_args.items[i];
soname = name;
// Use it as --name.
// Example: libsoundio.so.2
var prefix: usize = 0;
if (mem.startsWith(u8, soname, "lib")) {
if (mem.startsWith(u8, name, "lib")) {
prefix = 3;
}
var end: usize = soname.len;
if (mem.endsWith(u8, soname, ".so")) {
var end: usize = name.len;
if (mem.endsWith(u8, name, ".so")) {
end -= 3;
} else {
var found_digit = false;
while (end > 0 and std.ascii.isDigit(soname[end - 1])) {
while (end > 0 and std.ascii.isDigit(name[end - 1])) {
found_digit = true;
end -= 1;
}
if (found_digit and end > 0 and soname[end - 1] == '.') {
if (found_digit and end > 0 and name[end - 1] == '.') {
end -= 1;
} else {
end = soname.len;
end = name.len;
}
if (mem.endsWith(u8, soname[prefix..end], ".so")) {
if (mem.endsWith(u8, name[prefix..end], ".so")) {
end -= 3;
}
}
provided_name = soname[prefix..end];
provided_name = name[prefix..end];
} else if (mem.eql(u8, arg, "-rpath")) {
i += 1;
if (i >= linker_args.items.len) {
@ -1660,7 +1660,7 @@ fn buildOutputType(
.linker_script = linker_script,
.version_script = version_script,
.disable_c_depfile = disable_c_depfile,
.override_soname = override_soname,
.soname = soname,
.linker_gc_sections = linker_gc_sections,
.linker_allow_shlib_undefined = linker_allow_shlib_undefined,
.linker_bind_global_refs_locally = linker_bind_global_refs_locally,