| ... | ... | @@ -2294,9 +2294,10 @@ fn resolvePathInputLib( |
| 2294 | 2294 | const test_path: Path = pq.path; |
| 2295 | 2295 | // In the case of shared libraries, they might actually be "linker scripts" |
| 2296 | 2296 | // that contain references to other libraries. |
| 2297 | | if (pq.query.allow_so_scripts and target.ofmt == .elf and |
| 2298 | | Compilation.classifyFileExt(test_path.sub_path) == .shared_library) |
| 2299 | | { |
| 2297 | if (pq.query.allow_so_scripts and target.ofmt == .elf and switch (Compilation.classifyFileExt(test_path.sub_path)) { |
| 2298 | .static_library, .shared_library => true, |
| 2299 | else => false, |
| 2300 | }) { |
| 2300 | 2301 | var file = test_path.root_dir.handle.openFile(test_path.sub_path, .{}) catch |err| switch (err) { |
| 2301 | 2302 | error.FileNotFound => return .no_match, |
| 2302 | 2303 | else => |e| fatal("unable to search for {s} library '{'}': {s}", .{ |
| ... | ... | @@ -2304,14 +2305,13 @@ fn resolvePathInputLib( |
| 2304 | 2305 | }), |
| 2305 | 2306 | }; |
| 2306 | 2307 | errdefer file.close(); |
| 2307 | | try ld_script_bytes.resize(gpa, @sizeOf(std.elf.Elf64_Ehdr)); |
| 2308 | try ld_script_bytes.resize(gpa, @max(std.elf.MAGIC.len, std.elf.ARMAG.len)); |
| 2308 | 2309 | const n = file.preadAll(ld_script_bytes.items, 0) catch |err| fatal("failed to read '{'}': {s}", .{ |
| 2309 | 2310 | test_path, @errorName(err), |
| 2310 | 2311 | }); |
| 2311 | | elf_file: { |
| 2312 | | if (n != ld_script_bytes.items.len) break :elf_file; |
| 2313 | | if (!mem.eql(u8, ld_script_bytes.items[0..4], "\x7fELF")) break :elf_file; |
| 2314 | | // Appears to be an ELF file. |
| 2312 | const buf = ld_script_bytes.items[0..n]; |
| 2313 | if (mem.startsWith(u8, buf, std.elf.MAGIC) or mem.startsWith(u8, buf, std.elf.ARMAG)) { |
| 2314 | // Appears to be an ELF or archive file. |
| 2315 | 2315 | return finishResolveLibInput(resolved_inputs, test_path, file, link_mode, pq.query); |
| 2316 | 2316 | } |
| 2317 | 2317 | const stat = file.stat() catch |err| |
| ... | ... | @@ -2319,10 +2319,10 @@ fn resolvePathInputLib( |
| 2319 | 2319 | const size = std.math.cast(u32, stat.size) orelse |
| 2320 | 2320 | fatal("{}: linker script too big", .{test_path}); |
| 2321 | 2321 | try ld_script_bytes.resize(gpa, size); |
| 2322 | | const buf = ld_script_bytes.items[n..]; |
| 2323 | | const n2 = file.preadAll(buf, n) catch |err| |
| 2322 | const buf2 = ld_script_bytes.items[n..]; |
| 2323 | const n2 = file.preadAll(buf2, n) catch |err| |
| 2324 | 2324 | fatal("failed to read {}: {s}", .{ test_path, @errorName(err) }); |
| 2325 | | if (n2 != buf.len) fatal("failed to read {}: unexpected end of file", .{test_path}); |
| 2325 | if (n2 != buf2.len) fatal("failed to read {}: unexpected end of file", .{test_path}); |
| 2326 | 2326 | var diags = Diags.init(gpa); |
| 2327 | 2327 | defer diags.deinit(); |
| 2328 | 2328 | const ld_script_result = LdScript.parse(gpa, &diags, test_path, ld_script_bytes.items); |