| author | |
| committer | |
| log | 1aa0f8aa2f382fb56639ea6833a62c4b8b031247 |
| tree | 575223642adddd9ca12a89a2aca76eb309109766 |
| parent | e0f3975fc8a7afd8a613802321fd46e64d8970d5 |
3 files changed, 14 insertions(+), 11 deletions(-)
src/link/Coff.zig+8-4| ... | ... | @@ -1035,7 +1035,6 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1035 | 1035 | const unnamed_consts = gop.value_ptr; |
| 1036 | 1036 | |
| 1037 | 1037 | const atom_index = try self.createAtom(); |
| 1038 | const atom = self.getAtomPtr(atom_index); | |
| 1039 | 1038 | |
| 1040 | 1039 | const sym_name = blk: { |
| 1041 | 1040 | const decl_name = try decl.getFullyQualifiedName(mod); |
| ... | ... | @@ -1045,11 +1044,15 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1045 | 1044 | break :blk try std.fmt.allocPrint(gpa, "__unnamed_{s}_{d}", .{ decl_name, index }); |
| 1046 | 1045 | }; |
| 1047 | 1046 | defer gpa.free(sym_name); |
| 1048 | try self.setSymbolName(atom.getSymbolPtr(self), sym_name); | |
| 1049 | atom.getSymbolPtr(self).section_number = @intToEnum(coff.SectionNumber, self.rdata_section_index.? + 1); | |
| 1047 | { | |
| 1048 | const atom = self.getAtom(atom_index); | |
| 1049 | const sym = atom.getSymbolPtr(self); | |
| 1050 | try self.setSymbolName(sym, sym_name); | |
| 1051 | sym.section_number = @intToEnum(coff.SectionNumber, self.rdata_section_index.? + 1); | |
| 1052 | } | |
| 1050 | 1053 | |
| 1051 | 1054 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), tv, &code_buffer, .none, .{ |
| 1052 | .parent_atom_index = atom.getSymbolIndex().?, | |
| 1055 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | |
| 1053 | 1056 | }); |
| 1054 | 1057 | const code = switch (res) { |
| 1055 | 1058 | .ok => code_buffer.items, |
| ... | ... | @@ -1062,6 +1065,7 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1062 | 1065 | }; |
| 1063 | 1066 | |
| 1064 | 1067 | const required_alignment = tv.ty.abiAlignment(self.base.options.target); |
| 1068 | const atom = self.getAtomPtr(atom_index); | |
| 1065 | 1069 | atom.alignment = required_alignment; |
| 1066 | 1070 | atom.size = @intCast(u32, code.len); |
| 1067 | 1071 | atom.getSymbolPtr(self).value = try self.allocateAtom(atom_index, atom.size, atom.alignment); |
src/link/Elf.zig+4-5| ... | ... | @@ -2600,12 +2600,11 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2600 | 2600 | const name = self.shstrtab.get(name_str_index).?; |
| 2601 | 2601 | |
| 2602 | 2602 | const atom_index = try self.createAtom(); |
| 2603 | const atom = self.getAtomPtr(atom_index); | |
| 2604 | 2603 | |
| 2605 | 2604 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .{ |
| 2606 | 2605 | .none = {}, |
| 2607 | 2606 | }, .{ |
| 2608 | .parent_atom_index = atom.getSymbolIndex().?, | |
| 2607 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | |
| 2609 | 2608 | }); |
| 2610 | 2609 | const code = switch (res) { |
| 2611 | 2610 | .ok => code_buffer.items, |
| ... | ... | @@ -2620,7 +2619,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2620 | 2619 | const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); |
| 2621 | 2620 | const shdr_index = self.rodata_section_index.?; |
| 2622 | 2621 | const phdr_index = self.sections.items(.phdr_index)[shdr_index]; |
| 2623 | const local_sym = atom.getSymbolPtr(self); | |
| 2622 | const local_sym = self.getAtom(atom_index).getSymbolPtr(self); | |
| 2624 | 2623 | local_sym.st_name = name_str_index; |
| 2625 | 2624 | local_sym.st_info = (elf.STB_LOCAL << 4) | elf.STT_OBJECT; |
| 2626 | 2625 | local_sym.st_other = 0; |
| ... | ... | @@ -2631,14 +2630,14 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2631 | 2630 | |
| 2632 | 2631 | log.debug("allocated text block for {s} at 0x{x}", .{ name, local_sym.st_value }); |
| 2633 | 2632 | |
| 2634 | try self.writeSymbol(atom.getSymbolIndex().?); | |
| 2633 | try self.writeSymbol(self.getAtom(atom_index).getSymbolIndex().?); | |
| 2635 | 2634 | try unnamed_consts.append(gpa, atom_index); |
| 2636 | 2635 | |
| 2637 | 2636 | const section_offset = local_sym.st_value - self.program_headers.items[phdr_index].p_vaddr; |
| 2638 | 2637 | const file_offset = self.sections.items(.shdr)[shdr_index].sh_offset + section_offset; |
| 2639 | 2638 | try self.base.file.?.pwriteAll(code, file_offset); |
| 2640 | 2639 | |
| 2641 | return atom.getSymbolIndex().?; | |
| 2640 | return self.getAtom(atom_index).getSymbolIndex().?; | |
| 2642 | 2641 | } |
| 2643 | 2642 | |
| 2644 | 2643 | pub fn updateDeclExports( |
src/link/MachO.zig+2-2| ... | ... | @@ -2079,10 +2079,9 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 2079 | 2079 | log.debug("allocating symbol indexes for {?s}", .{name}); |
| 2080 | 2080 | |
| 2081 | 2081 | const atom_index = try self.createAtom(); |
| 2082 | const atom = self.getAtomPtr(atom_index); | |
| 2083 | 2082 | |
| 2084 | 2083 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(), typed_value, &code_buffer, .none, .{ |
| 2085 | .parent_atom_index = atom.getSymbolIndex().?, | |
| 2084 | .parent_atom_index = self.getAtom(atom_index).getSymbolIndex().?, | |
| 2086 | 2085 | }); |
| 2087 | 2086 | const code = switch (res) { |
| 2088 | 2087 | .ok => code_buffer.items, |
| ... | ... | @@ -2095,6 +2094,7 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl_index: Modu |
| 2095 | 2094 | }; |
| 2096 | 2095 | |
| 2097 | 2096 | const required_alignment = typed_value.ty.abiAlignment(self.base.options.target); |
| 2097 | const atom = self.getAtomPtr(atom_index); | |
| 2098 | 2098 | atom.size = code.len; |
| 2099 | 2099 | atom.alignment = required_alignment; |
| 2100 | 2100 | // TODO: work out logic for disambiguating functions from function pointers |