@@ -579,6 +579,8 @@ pub fn updateSymtabSize(self: *ZigObject, elf_file: *Elf) !void {
579
579
for (self .local_symbols .items ) | index | {
580
580
const local = & self .symbols .items [index ];
581
581
if (local .atom (elf_file )) | atom_ptr | if (! atom_ptr .alive ) continue ;
582
+ const name = local .name (elf_file );
583
+ assert (name .len > 0 );
582
584
const esym = local .elfSym (elf_file );
583
585
switch (esym .st_type ()) {
584
586
elf .STT_SECTION , elf .STT_NOTYPE = > continue ,
@@ -587,7 +589,7 @@ pub fn updateSymtabSize(self: *ZigObject, elf_file: *Elf) !void {
587
589
local .flags .output_symtab = true ;
588
590
local .addExtra (.{ .symtab = self .output_symtab_ctx .nlocals }, elf_file );
589
591
self .output_symtab_ctx .nlocals += 1 ;
590
- self .output_symtab_ctx .strsize += @as (u32 , @intCast (local . name ( elf_file ) .len )) + 1 ;
592
+ self .output_symtab_ctx .strsize += @as (u32 , @intCast (name .len )) + 1 ;
591
593
}
592
594
593
595
for (self .global_symbols .items , self .symbols_resolver .items ) | index , resolv | {
@@ -662,10 +664,22 @@ pub fn codeAlloc(self: *ZigObject, elf_file: *Elf, atom_index: Atom.Index) ![]u8
662
664
pub fn getDeclVAddr (
663
665
self : * ZigObject ,
664
666
elf_file : * Elf ,
667
+ pt : Zcu.PerThread ,
665
668
decl_index : InternPool.DeclIndex ,
666
669
reloc_info : link.File.RelocInfo ,
667
670
) ! u64 {
668
- const this_sym_index = try self .getOrCreateMetadataForDecl (elf_file , decl_index );
671
+ const zcu = pt .zcu ;
672
+ const ip = & zcu .intern_pool ;
673
+ const decl = zcu .declPtr (decl_index );
674
+ log .debug ("getDeclVAddr {}({d})" , .{ decl .fqn .fmt (ip ), decl_index });
675
+ const this_sym_index = if (decl .isExtern (zcu )) blk : {
676
+ const name = decl .name .toSlice (ip );
677
+ const lib_name = if (decl .getOwnedExternFunc (zcu )) | ext_fn |
678
+ ext_fn .lib_name .toSlice (ip )
679
+ else
680
+ decl .getOwnedVariable (zcu ).? .lib_name .toSlice (ip );
681
+ break :blk try self .getGlobalSymbol (elf_file , name , lib_name );
682
+ } else try self .getOrCreateMetadataForDecl (elf_file , decl_index );
669
683
const this_sym = self .symbol (this_sym_index );
670
684
const vaddr = this_sym .address (.{}, elf_file );
671
685
const parent_atom = self .symbol (reloc_info .parent_atom_index ).atom (elf_file ).? ;
@@ -808,10 +822,8 @@ fn freeDeclMetadata(self: *ZigObject, elf_file: *Elf, sym_index: Symbol.Index) v
808
822
809
823
pub fn freeDecl (self : * ZigObject , elf_file : * Elf , decl_index : InternPool.DeclIndex ) void {
810
824
const gpa = elf_file .base .comp .gpa ;
811
- const mod = elf_file .base .comp .module .? ;
812
- const decl = mod .declPtr (decl_index );
813
825
814
- log .debug ("freeDecl {*} " , .{decl });
826
+ log .debug ("freeDecl ({d}) " , .{decl_index });
815
827
816
828
if (self .decls .fetchRemove (decl_index )) | const_kv | {
817
829
var kv = const_kv ;
@@ -921,7 +933,7 @@ fn updateDeclCode(
921
933
const ip = & mod .intern_pool ;
922
934
const decl = mod .declPtr (decl_index );
923
935
924
- log .debug ("updateDeclCode {}{*} " , .{ decl .fqn .fmt (ip ), decl });
936
+ log .debug ("updateDeclCode {}({d}) " , .{ decl .fqn .fmt (ip ), decl_index });
925
937
926
938
const required_alignment = decl .getAlignment (pt ).max (
927
939
target_util .minFunctionAlignment (mod .getTarget ()),
@@ -1021,7 +1033,7 @@ fn updateTlv(
1021
1033
const gpa = mod .gpa ;
1022
1034
const decl = mod .declPtr (decl_index );
1023
1035
1024
- log .debug ("updateTlv {} ({* })" , .{ decl .fqn .fmt (ip ), decl });
1036
+ log .debug ("updateTlv {}({d })" , .{ decl .fqn .fmt (ip ), decl_index });
1025
1037
1026
1038
const required_alignment = decl .getAlignment (pt );
1027
1039
@@ -1075,11 +1087,14 @@ pub fn updateFunc(
1075
1087
defer tracy .end ();
1076
1088
1077
1089
const mod = pt .zcu ;
1090
+ const ip = & mod .intern_pool ;
1078
1091
const gpa = elf_file .base .comp .gpa ;
1079
1092
const func = mod .funcInfo (func_index );
1080
1093
const decl_index = func .owner_decl ;
1081
1094
const decl = mod .declPtr (decl_index );
1082
1095
1096
+ log .debug ("updateFunc {}({d})" , .{ decl .fqn .fmt (ip ), decl_index });
1097
+
1083
1098
const sym_index = try self .getOrCreateMetadataForDecl (elf_file , decl_index );
1084
1099
self .freeUnnamedConsts (elf_file , decl_index );
1085
1100
self .symbol (sym_index ).atom (elf_file ).? .freeRelocs (elf_file );
@@ -1137,12 +1152,12 @@ pub fn updateDecl(
1137
1152
defer tracy .end ();
1138
1153
1139
1154
const mod = pt .zcu ;
1155
+ const ip = & mod .intern_pool ;
1140
1156
const decl = mod .declPtr (decl_index );
1141
1157
1142
- if (decl .val .getExternFunc (mod )) | _ | {
1143
- return ;
1144
- }
1158
+ log .debug ("updateDecl {}({d})" , .{ decl .fqn .fmt (ip ), decl_index });
1145
1159
1160
+ if (decl .val .getExternFunc (mod )) | _ | return ;
1146
1161
if (decl .isExtern (mod )) {
1147
1162
// Extern variable gets a .got entry only.
1148
1163
const variable = decl .getOwnedVariable (mod ).? ;
@@ -1483,7 +1498,7 @@ pub fn updateDeclLineNumber(
1483
1498
1484
1499
const decl = pt .zcu .declPtr (decl_index );
1485
1500
1486
- log .debug ("updateDeclLineNumber {}{*} " , .{ decl .fqn .fmt (& pt .zcu .intern_pool ), decl });
1501
+ log .debug ("updateDeclLineNumber {}({d}) " , .{ decl .fqn .fmt (& pt .zcu .intern_pool ), decl_index });
1487
1502
1488
1503
if (self .dwarf ) | * dw | {
1489
1504
try dw .updateDeclLineNumber (pt .zcu , decl_index );
0 commit comments