@@ -11,14 +11,14 @@ file: File.Index = 0,
11
11
12
12
/// Atom containing this symbol if any.
13
13
/// Use `getAtom` to get the pointer to the atom.
14
- atom_ref : Elf.Ref = .{},
14
+ ref : Elf.Ref = .{},
15
15
16
16
/// Assigned output section index for this symbol.
17
17
shndx : u32 = 0 ,
18
18
19
19
/// Index of the source symbol this symbol references.
20
- /// Use `getSourceSymbol ` to pull the source symbol from the relevant file.
21
- sym_idx : Index = 0 ,
20
+ /// Use `getElfSym ` to pull the source symbol from the relevant file.
21
+ esym_idx : Index = 0 ,
22
22
23
23
/// Index of the source version symbol this symbol references if any.
24
24
/// If the symbol is unversioned it will have either VER_NDX_LOCAL or VER_NDX_GLOBAL.
@@ -31,12 +31,12 @@ extra: u32 = 0,
31
31
32
32
pub fn isAbs (symbol : Symbol , elf_file : * Elf ) bool {
33
33
const file = symbol .getFile (elf_file ).? ;
34
- if (file == .shared ) return symbol .getSourceSymbol (elf_file ).st_shndx == elf .SHN_ABS ;
34
+ if (file == .shared ) return symbol .getElfSym (elf_file ).st_shndx == elf .SHN_ABS ;
35
35
return ! symbol .flags .import and symbol .getAtom (elf_file ) == null and symbol .getMergeSubsection (elf_file ) == null and symbol .shndx == 0 and file != .internal ;
36
36
}
37
37
38
38
pub fn isLocal (symbol : Symbol , elf_file : * Elf ) bool {
39
- if (elf_file .options .relocatable ) return symbol .getSourceSymbol (elf_file ).st_bind () == elf .STB_LOCAL ;
39
+ if (elf_file .options .relocatable ) return symbol .getElfSym (elf_file ).st_bind () == elf .STB_LOCAL ;
40
40
return ! (symbol .flags .import or symbol .flags .@"export" );
41
41
}
42
42
@@ -46,39 +46,42 @@ pub inline fn isIFunc(symbol: Symbol, elf_file: *Elf) bool {
46
46
47
47
pub fn getType (symbol : Symbol , elf_file : * Elf ) u4 {
48
48
const file = symbol .getFile (elf_file ).? ;
49
- const s_sym = symbol .getSourceSymbol (elf_file );
49
+ const s_sym = symbol .getElfSym (elf_file );
50
50
if (s_sym .st_type () == elf .STT_GNU_IFUNC and file == .shared ) return elf .STT_FUNC ;
51
51
return s_sym .st_type ();
52
52
}
53
53
54
54
pub fn getName (symbol : Symbol , elf_file : * Elf ) [:0 ]const u8 {
55
- return elf_file .string_intern .getAssumeExists (symbol .name );
55
+ return switch (symbol .getFile (elf_file ).? ) {
56
+ inline else = > | x | x .getString (symbol .name ),
57
+ };
56
58
}
57
59
58
60
pub fn getAtom (symbol : Symbol , elf_file : * Elf ) ? * Atom {
59
- return elf_file .getAtom (symbol .atom_ref );
61
+ if (symbol .flags .merge_subsection ) return null ;
62
+ return elf_file .getAtom (symbol .ref );
60
63
}
61
64
62
65
pub fn getMergeSubsection (symbol : Symbol , elf_file : * Elf ) ? * MergeSubsection {
63
66
if (! symbol .flags .merge_subsection ) return null ;
64
- const extra = symbol .getExtra (elf_file ).? ;
67
+ const extra = symbol .getExtra (elf_file );
65
68
return elf_file .getMergeSubsection (extra .subsection );
66
69
}
67
70
68
- pub inline fn getFile (symbol : Symbol , elf_file : * Elf ) ? File {
71
+ pub fn getFile (symbol : Symbol , elf_file : * Elf ) ? File {
69
72
return elf_file .getFile (symbol .file );
70
73
}
71
74
72
- pub fn getSourceSymbol (symbol : Symbol , elf_file : * Elf ) elf.Elf64_Sym {
75
+ pub fn getElfSym (symbol : Symbol , elf_file : * Elf ) elf.Elf64_Sym {
73
76
const file = symbol .getFile (elf_file ).? ;
74
77
return switch (file ) {
75
- inline else = > | x | x .symtab .items [symbol .sym_idx ],
78
+ inline else = > | x | x .symtab .items [symbol .esym_idx ],
76
79
};
77
80
}
78
81
79
82
pub fn getSymbolRank (symbol : Symbol , elf_file : * Elf ) u32 {
80
83
const file = symbol .getFile (elf_file ) orelse return std .math .maxInt (u32 );
81
- const sym = symbol .getSourceSymbol (elf_file );
84
+ const sym = symbol .getElfSym (elf_file );
82
85
const in_archive = switch (file ) {
83
86
.object = > | x | ! x .alive ,
84
87
else = > false ,
@@ -116,7 +119,7 @@ pub fn getAddress(symbol: Symbol, opts: struct {
116
119
if (mem .startsWith (u8 , sym_name , "__EH_FRAME_BEGIN__" ) or
117
120
mem .startsWith (u8 , sym_name , "__EH_FRAME_LIST__" ) or
118
121
mem .startsWith (u8 , sym_name , ".eh_frame_seg" ) or
119
- symbol .getSourceSymbol (elf_file ).st_type () == elf .STT_SECTION )
122
+ symbol .getElfSym (elf_file ).st_type () == elf .STT_SECTION )
120
123
{
121
124
return @intCast (sh_addr );
122
125
}
@@ -143,36 +146,36 @@ pub fn getOutputSymtabIndex(symbol: Symbol, elf_file: *Elf) ?u32 {
143
146
const symtab_ctx = switch (file ) {
144
147
inline else = > | x | x .output_symtab_ctx ,
145
148
};
146
- const idx = symbol .getExtra (elf_file ).? . symtab ;
149
+ const idx = symbol .getExtra (elf_file ).symtab ;
147
150
return if (symbol .isLocal (elf_file )) idx + symtab_ctx .ilocal else idx + symtab_ctx .iglobal ;
148
151
}
149
152
150
153
pub fn getGotAddress (symbol : Symbol , elf_file : * Elf ) i64 {
151
154
if (! symbol .flags .got ) return 0 ;
152
- const extra = symbol .getExtra (elf_file ).? ;
155
+ const extra = symbol .getExtra (elf_file );
153
156
const entry = elf_file .got .entries .items [extra .got ];
154
157
return entry .getAddress (elf_file );
155
158
}
156
159
157
160
pub fn getPltGotAddress (symbol : Symbol , elf_file : * Elf ) i64 {
158
161
if (! (symbol .flags .plt and symbol .flags .got )) return 0 ;
159
- const extra = symbol .getExtra (elf_file ).? ;
162
+ const extra = symbol .getExtra (elf_file );
160
163
const shdr = elf_file .sections .items (.shdr )[elf_file .plt_got_sect_index .? ];
161
164
const cpu_arch = elf_file .options .cpu_arch .? ;
162
165
return @intCast (shdr .sh_addr + extra .plt_got * PltGotSection .entrySize (cpu_arch ));
163
166
}
164
167
165
168
pub fn getPltAddress (symbol : Symbol , elf_file : * Elf ) i64 {
166
169
if (! symbol .flags .plt ) return 0 ;
167
- const extra = symbol .getExtra (elf_file ).? ;
170
+ const extra = symbol .getExtra (elf_file );
168
171
const shdr = elf_file .sections .items (.shdr )[elf_file .plt_sect_index .? ];
169
172
const cpu_arch = elf_file .options .cpu_arch .? ;
170
173
return @intCast (shdr .sh_addr + extra .plt * PltSection .entrySize (cpu_arch ) + PltSection .preambleSize (cpu_arch ));
171
174
}
172
175
173
176
pub fn getGotPltAddress (symbol : Symbol , elf_file : * Elf ) i64 {
174
177
if (! symbol .flags .plt ) return 0 ;
175
- const extra = symbol .getExtra (elf_file ).? ;
178
+ const extra = symbol .getExtra (elf_file );
176
179
const shdr = elf_file .sections .items (.shdr )[elf_file .got_plt_sect_index .? ];
177
180
return @intCast (shdr .sh_addr + extra .plt * 8 + GotPltSection .preamble_size );
178
181
}
@@ -185,29 +188,29 @@ pub fn getCopyRelAddress(symbol: Symbol, elf_file: *Elf) i64 {
185
188
186
189
pub fn getTlsGdAddress (symbol : Symbol , elf_file : * Elf ) i64 {
187
190
if (! symbol .flags .tlsgd ) return 0 ;
188
- const extra = symbol .getExtra (elf_file ).? ;
191
+ const extra = symbol .getExtra (elf_file );
189
192
const entry = elf_file .got .entries .items [extra .tlsgd ];
190
193
return entry .getAddress (elf_file );
191
194
}
192
195
193
196
pub fn getGotTpAddress (symbol : Symbol , elf_file : * Elf ) i64 {
194
197
if (! symbol .flags .gottp ) return 0 ;
195
- const extra = symbol .getExtra (elf_file ).? ;
198
+ const extra = symbol .getExtra (elf_file );
196
199
const entry = elf_file .got .entries .items [extra .gottp ];
197
200
return entry .getAddress (elf_file );
198
201
}
199
202
200
203
pub fn getTlsDescAddress (symbol : Symbol , elf_file : * Elf ) i64 {
201
204
if (! symbol .flags .tlsdesc ) return 0 ;
202
- const extra = symbol .getExtra (elf_file ).? ;
205
+ const extra = symbol .getExtra (elf_file );
203
206
const entry = elf_file .got .entries .items [extra .tlsdesc ];
204
207
return entry .getAddress (elf_file );
205
208
}
206
209
207
210
pub fn getAlignment (symbol : Symbol , elf_file : * Elf ) ! u64 {
208
211
const file = symbol .getFile (elf_file ) orelse return 0 ;
209
212
const shared = file .shared ;
210
- const s_sym = symbol .getSourceSymbol (elf_file );
213
+ const s_sym = symbol .getElfSym (elf_file );
211
214
const shdr = shared .shdrs .items [s_sym .st_shndx ];
212
215
const alignment = @max (1 , shdr .sh_addralign );
213
216
return if (s_sym .st_value == 0 )
@@ -229,11 +232,8 @@ const AddExtraOpts = struct {
229
232
subsection : ? u32 = null ,
230
233
};
231
234
232
- pub fn addExtra (symbol : * Symbol , opts : AddExtraOpts , elf_file : * Elf ) ! void {
233
- if (symbol .getExtra (elf_file ) == null ) {
234
- symbol .extra = try elf_file .addSymbolExtra (.{});
235
- }
236
- var extra = symbol .getExtra (elf_file ).? ;
235
+ pub fn addExtra (symbol : * Symbol , opts : AddExtraOpts , elf_file : * Elf ) void {
236
+ var extra = symbol .getExtra (elf_file );
237
237
inline for (@typeInfo (@TypeOf (opts )).@"struct" .fields ) | field | {
238
238
if (@field (opts , field .name )) | x | {
239
239
@field (extra , field .name ) = x ;
@@ -242,17 +242,21 @@ pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {
242
242
symbol .setExtra (extra , elf_file );
243
243
}
244
244
245
- pub inline fn getExtra (symbol : Symbol , elf_file : * Elf ) ? Extra {
246
- return elf_file .getSymbolExtra (symbol .extra );
245
+ pub fn getExtra (symbol : Symbol , elf_file : * Elf ) Extra {
246
+ return switch (symbol .getFile (elf_file ).? ) {
247
+ inline else = > | x | x .getSymbolExtra (symbol .extra ),
248
+ };
247
249
}
248
250
249
- pub inline fn setExtra (symbol : Symbol , extra : Extra , elf_file : * Elf ) void {
250
- elf_file .setSymbolExtra (symbol .extra , extra );
251
+ pub fn setExtra (symbol : Symbol , extra : Extra , elf_file : * Elf ) void {
252
+ return switch (symbol .getFile (elf_file ).? ) {
253
+ inline else = > | x | x .setSymbolExtra (symbol .extra , extra ),
254
+ };
251
255
}
252
256
253
257
pub fn setOutputSym (symbol : Symbol , elf_file : * Elf , out : * elf.Elf64_Sym ) void {
254
258
const file = symbol .getFile (elf_file ).? ;
255
- const s_sym = symbol .getSourceSymbol (elf_file );
259
+ const s_sym = symbol .getElfSym (elf_file );
256
260
const st_type = symbol .getType (elf_file );
257
261
const st_bind : u8 = blk : {
258
262
if (symbol .isLocal (elf_file )) break :blk 0 ;
@@ -347,10 +351,10 @@ fn format2(
347
351
_ = options ;
348
352
_ = unused_fmt_string ;
349
353
const symbol = ctx .symbol ;
350
- try writer .print ("%{d} : {s} : @{x}" , .{ symbol .sym_idx , symbol .fmtName (ctx .elf_file ), symbol .getAddress (.{}, ctx .elf_file ) });
354
+ try writer .print ("%{d} : {s} : @{x}" , .{ symbol .esym_idx , symbol .fmtName (ctx .elf_file ), symbol .getAddress (.{}, ctx .elf_file ) });
351
355
if (symbol .getFile (ctx .elf_file )) | file | {
352
356
if (symbol .isAbs (ctx .elf_file )) {
353
- if (symbol .getSourceSymbol (ctx .elf_file ).st_shndx == elf .SHN_UNDEF ) {
357
+ if (symbol .getElfSym (ctx .elf_file ).st_shndx == elf .SHN_UNDEF ) {
354
358
try writer .writeAll (" : undef" );
355
359
} else {
356
360
try writer .writeAll (" : absolute" );
0 commit comments