authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 07:19:25+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 13:34:26+02:00
log6ec8b15918dcd692f88875843a51a0514e315d9d
treec63f3721e1a1bf67e02c92833a8bbe8d430eb73c
parent8c76a61ef541cf285a82fcc928face4082606c03

elf: fix emitting static lib when ZigObject is present


2 files changed, 9 insertions(+), 13 deletions(-)

src/link/Elf/relocatable.zig+8-13
......@@ -18,7 +18,7 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co
1818 }
1919
2020 for (positionals.items) |obj| {
21 parsePositional(elf_file, obj.path) catch |err| switch (err) {
21 parsePositionalStaticLib(elf_file, obj.path) catch |err| switch (err) {
2222 error.MalformedObject,
2323 error.MalformedArchive,
2424 error.InvalidMachineType,
......@@ -38,17 +38,12 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co
3838 // First, we flush relocatable object file generated with our backends.
3939 if (elf_file.zigObjectPtr()) |zig_object| {
4040 try zig_object.resolveSymbols(elf_file);
41 elf_file.markEhFrameAtomsDead();
4142 try elf_file.addCommentString();
4243 try elf_file.finalizeMergeSections();
4344 zig_object.claimUnresolvedRelocatable(elf_file);
4445
45 for (elf_file.merge_sections.items) |*msec| {
46 if (msec.finalized_subsections.items.len == 0) continue;
47 try msec.initOutputSection(elf_file);
48 }
49
50 try elf_file.initSymtab();
51 try elf_file.initShStrtab();
46 try initSections(elf_file);
5247 try elf_file.sortShdrs();
5348 try zig_object.addAtomsToRelaSections(elf_file);
5449 try elf_file.updateMergeSectionSizes();
......@@ -229,17 +224,17 @@ pub fn flushObject(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]const
229224 if (elf_file.base.hasErrors()) return error.FlushFailure;
230225}
231226
232fn parsePositional(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
227fn parsePositionalStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
233228 if (try Object.isObject(path)) {
234 try parseObject(elf_file, path);
229 try parseObjectStaticLib(elf_file, path);
235230 } else if (try Archive.isArchive(path)) {
236 try parseArchive(elf_file, path);
231 try parseArchiveStaticLib(elf_file, path);
237232 } else return error.UnknownFileType;
238233 // TODO: should we check for LD script?
239234 // Actually, should we even unpack an archive?
240235}
241236
242fn parseObject(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
237fn parseObjectStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
243238 const gpa = elf_file.base.comp.gpa;
244239 const handle = try std.fs.cwd().openFile(path, .{});
245240 const fh = try elf_file.addFileHandle(handle);
......@@ -256,7 +251,7 @@ fn parseObject(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
256251 try object.parseAr(elf_file);
257252}
258253
259fn parseArchive(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
254fn parseArchiveStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void {
260255 const gpa = elf_file.base.comp.gpa;
261256 const handle = try std.fs.cwd().openFile(path, .{});
262257 const fh = try elf_file.addFileHandle(handle);
test/link/elf.zig+1
......@@ -55,6 +55,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
5555
5656 // Exercise linker in ar mode
5757 elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target }));
58 elf_step.dependOn(testEmitStaticLibZig(b, .{ .target = musl_target }));
5859
5960 // Exercise linker with LLVM backend
6061 // musl tests