| ... | @@ -18,7 +18,7 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co | ... | @@ -18,7 +18,7 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co |
| 18 | } | 18 | } |
| 19 | | 19 | |
| 20 | for (positionals.items) |obj| { | 20 | for (positionals.items) |obj| { |
| 21 | parsePositional(elf_file, obj.path) catch |err| switch (err) { | 21 | parsePositionalStaticLib(elf_file, obj.path) catch |err| switch (err) { |
| 22 | error.MalformedObject, | 22 | error.MalformedObject, |
| 23 | error.MalformedArchive, | 23 | error.MalformedArchive, |
| 24 | error.InvalidMachineType, | 24 | error.InvalidMachineType, |
| ... | @@ -38,17 +38,12 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co | ... | @@ -38,17 +38,12 @@ pub fn flushStaticLib(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]co |
| 38 | // First, we flush relocatable object file generated with our backends. | 38 | // First, we flush relocatable object file generated with our backends. |
| 39 | if (elf_file.zigObjectPtr()) |zig_object| { | 39 | if (elf_file.zigObjectPtr()) |zig_object| { |
| 40 | try zig_object.resolveSymbols(elf_file); | 40 | try zig_object.resolveSymbols(elf_file); |
| | 41 | elf_file.markEhFrameAtomsDead(); |
| 41 | try elf_file.addCommentString(); | 42 | try elf_file.addCommentString(); |
| 42 | try elf_file.finalizeMergeSections(); | 43 | try elf_file.finalizeMergeSections(); |
| 43 | zig_object.claimUnresolvedRelocatable(elf_file); | 44 | zig_object.claimUnresolvedRelocatable(elf_file); |
| 44 | | 45 | |
| 45 | for (elf_file.merge_sections.items) |*msec| { | 46 | try initSections(elf_file); |
| 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(); | | |
| 52 | try elf_file.sortShdrs(); | 47 | try elf_file.sortShdrs(); |
| 53 | try zig_object.addAtomsToRelaSections(elf_file); | 48 | try zig_object.addAtomsToRelaSections(elf_file); |
| 54 | try elf_file.updateMergeSectionSizes(); | 49 | try elf_file.updateMergeSectionSizes(); |
| ... | @@ -229,17 +224,17 @@ pub fn flushObject(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]const | ... | @@ -229,17 +224,17 @@ pub fn flushObject(elf_file: *Elf, comp: *Compilation, module_obj_path: ?[]const |
| 229 | if (elf_file.base.hasErrors()) return error.FlushFailure; | 224 | if (elf_file.base.hasErrors()) return error.FlushFailure; |
| 230 | } | 225 | } |
| 231 | | 226 | |
| 232 | fn parsePositional(elf_file: *Elf, path: []const u8) Elf.ParseError!void { | 227 | fn parsePositionalStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void { |
| 233 | if (try Object.isObject(path)) { | 228 | if (try Object.isObject(path)) { |
| 234 | try parseObject(elf_file, path); | 229 | try parseObjectStaticLib(elf_file, path); |
| 235 | } else if (try Archive.isArchive(path)) { | 230 | } else if (try Archive.isArchive(path)) { |
| 236 | try parseArchive(elf_file, path); | 231 | try parseArchiveStaticLib(elf_file, path); |
| 237 | } else return error.UnknownFileType; | 232 | } else return error.UnknownFileType; |
| 238 | // TODO: should we check for LD script? | 233 | // TODO: should we check for LD script? |
| 239 | // Actually, should we even unpack an archive? | 234 | // Actually, should we even unpack an archive? |
| 240 | } | 235 | } |
| 241 | | 236 | |
| 242 | fn parseObject(elf_file: *Elf, path: []const u8) Elf.ParseError!void { | 237 | fn parseObjectStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void { |
| 243 | const gpa = elf_file.base.comp.gpa; | 238 | const gpa = elf_file.base.comp.gpa; |
| 244 | const handle = try std.fs.cwd().openFile(path, .{}); | 239 | const handle = try std.fs.cwd().openFile(path, .{}); |
| 245 | const fh = try elf_file.addFileHandle(handle); | 240 | const fh = try elf_file.addFileHandle(handle); |
| ... | @@ -256,7 +251,7 @@ fn parseObject(elf_file: *Elf, path: []const u8) Elf.ParseError!void { | ... | @@ -256,7 +251,7 @@ fn parseObject(elf_file: *Elf, path: []const u8) Elf.ParseError!void { |
| 256 | try object.parseAr(elf_file); | 251 | try object.parseAr(elf_file); |
| 257 | } | 252 | } |
| 258 | | 253 | |
| 259 | fn parseArchive(elf_file: *Elf, path: []const u8) Elf.ParseError!void { | 254 | fn parseArchiveStaticLib(elf_file: *Elf, path: []const u8) Elf.ParseError!void { |
| 260 | const gpa = elf_file.base.comp.gpa; | 255 | const gpa = elf_file.base.comp.gpa; |
| 261 | const handle = try std.fs.cwd().openFile(path, .{}); | 256 | const handle = try std.fs.cwd().openFile(path, .{}); |
| 262 | const fh = try elf_file.addFileHandle(handle); | 257 | const fh = try elf_file.addFileHandle(handle); |