@@ -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,41 @@ 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
+ return elf_file .getAtom (symbol .ref );
60
62
}
61
63
62
64
pub fn getMergeSubsection (symbol : Symbol , elf_file : * Elf ) ? * MergeSubsection {
63
65
if (! symbol .flags .merge_subsection ) return null ;
64
- const extra = symbol .getExtra (elf_file ).? ;
66
+ const extra = symbol .getExtra (elf_file );
65
67
return elf_file .getMergeSubsection (extra .subsection );
66
68
}
67
69
68
- pub inline fn getFile (symbol : Symbol , elf_file : * Elf ) ? File {
70
+ pub fn getFile (symbol : Symbol , elf_file : * Elf ) ? File {
69
71
return elf_file .getFile (symbol .file );
70
72
}
71
73
72
- pub fn getSourceSymbol (symbol : Symbol , elf_file : * Elf ) elf.Elf64_Sym {
74
+ pub fn getElfSym (symbol : Symbol , elf_file : * Elf ) elf.Elf64_Sym {
73
75
const file = symbol .getFile (elf_file ).? ;
74
76
return switch (file ) {
75
- inline else = > | x | x .symtab .items [symbol .sym_idx ],
77
+ inline else = > | x | x .symtab .items [symbol .esym_idx ],
76
78
};
77
79
}
78
80
79
81
pub fn getSymbolRank (symbol : Symbol , elf_file : * Elf ) u32 {
80
82
const file = symbol .getFile (elf_file ) orelse return std .math .maxInt (u32 );
81
- const sym = symbol .getSourceSymbol (elf_file );
83
+ const sym = symbol .getElfSym (elf_file );
82
84
const in_archive = switch (file ) {
83
85
.object = > | x | ! x .alive ,
84
86
else = > false ,
@@ -116,7 +118,7 @@ pub fn getAddress(symbol: Symbol, opts: struct {
116
118
if (mem .startsWith (u8 , sym_name , "__EH_FRAME_BEGIN__" ) or
117
119
mem .startsWith (u8 , sym_name , "__EH_FRAME_LIST__" ) or
118
120
mem .startsWith (u8 , sym_name , ".eh_frame_seg" ) or
119
- symbol .getSourceSymbol (elf_file ).st_type () == elf .STT_SECTION )
121
+ symbol .getElfSym (elf_file ).st_type () == elf .STT_SECTION )
120
122
{
121
123
return @intCast (sh_addr );
122
124
}
@@ -143,36 +145,36 @@ pub fn getOutputSymtabIndex(symbol: Symbol, elf_file: *Elf) ?u32 {
143
145
const symtab_ctx = switch (file ) {
144
146
inline else = > | x | x .output_symtab_ctx ,
145
147
};
146
- const idx = symbol .getExtra (elf_file ).? . symtab ;
148
+ const idx = symbol .getExtra (elf_file ).symtab ;
147
149
return if (symbol .isLocal (elf_file )) idx + symtab_ctx .ilocal else idx + symtab_ctx .iglobal ;
148
150
}
149
151
150
152
pub fn getGotAddress (symbol : Symbol , elf_file : * Elf ) i64 {
151
153
if (! symbol .flags .got ) return 0 ;
152
- const extra = symbol .getExtra (elf_file ).? ;
154
+ const extra = symbol .getExtra (elf_file );
153
155
const entry = elf_file .got .entries .items [extra .got ];
154
156
return entry .getAddress (elf_file );
155
157
}
156
158
157
159
pub fn getPltGotAddress (symbol : Symbol , elf_file : * Elf ) i64 {
158
160
if (! (symbol .flags .plt and symbol .flags .got )) return 0 ;
159
- const extra = symbol .getExtra (elf_file ).? ;
161
+ const extra = symbol .getExtra (elf_file );
160
162
const shdr = elf_file .sections .items (.shdr )[elf_file .plt_got_sect_index .? ];
161
163
const cpu_arch = elf_file .options .cpu_arch .? ;
162
164
return @intCast (shdr .sh_addr + extra .plt_got * PltGotSection .entrySize (cpu_arch ));
163
165
}
164
166
165
167
pub fn getPltAddress (symbol : Symbol , elf_file : * Elf ) i64 {
166
168
if (! symbol .flags .plt ) return 0 ;
167
- const extra = symbol .getExtra (elf_file ).? ;
169
+ const extra = symbol .getExtra (elf_file );
168
170
const shdr = elf_file .sections .items (.shdr )[elf_file .plt_sect_index .? ];
169
171
const cpu_arch = elf_file .options .cpu_arch .? ;
170
172
return @intCast (shdr .sh_addr + extra .plt * PltSection .entrySize (cpu_arch ) + PltSection .preambleSize (cpu_arch ));
171
173
}
172
174
173
175
pub fn getGotPltAddress (symbol : Symbol , elf_file : * Elf ) i64 {
174
176
if (! symbol .flags .plt ) return 0 ;
175
- const extra = symbol .getExtra (elf_file ).? ;
177
+ const extra = symbol .getExtra (elf_file );
176
178
const shdr = elf_file .sections .items (.shdr )[elf_file .got_plt_sect_index .? ];
177
179
return @intCast (shdr .sh_addr + extra .plt * 8 + GotPltSection .preamble_size );
178
180
}
@@ -185,29 +187,29 @@ pub fn getCopyRelAddress(symbol: Symbol, elf_file: *Elf) i64 {
185
187
186
188
pub fn getTlsGdAddress (symbol : Symbol , elf_file : * Elf ) i64 {
187
189
if (! symbol .flags .tlsgd ) return 0 ;
188
- const extra = symbol .getExtra (elf_file ).? ;
190
+ const extra = symbol .getExtra (elf_file );
189
191
const entry = elf_file .got .entries .items [extra .tlsgd ];
190
192
return entry .getAddress (elf_file );
191
193
}
192
194
193
195
pub fn getGotTpAddress (symbol : Symbol , elf_file : * Elf ) i64 {
194
196
if (! symbol .flags .gottp ) return 0 ;
195
- const extra = symbol .getExtra (elf_file ).? ;
197
+ const extra = symbol .getExtra (elf_file );
196
198
const entry = elf_file .got .entries .items [extra .gottp ];
197
199
return entry .getAddress (elf_file );
198
200
}
199
201
200
202
pub fn getTlsDescAddress (symbol : Symbol , elf_file : * Elf ) i64 {
201
203
if (! symbol .flags .tlsdesc ) return 0 ;
202
- const extra = symbol .getExtra (elf_file ).? ;
204
+ const extra = symbol .getExtra (elf_file );
203
205
const entry = elf_file .got .entries .items [extra .tlsdesc ];
204
206
return entry .getAddress (elf_file );
205
207
}
206
208
207
209
pub fn getAlignment (symbol : Symbol , elf_file : * Elf ) ! u64 {
208
210
const file = symbol .getFile (elf_file ) orelse return 0 ;
209
211
const shared = file .shared ;
210
- const s_sym = symbol .getSourceSymbol (elf_file );
212
+ const s_sym = symbol .getElfSym (elf_file );
211
213
const shdr = shared .shdrs .items [s_sym .st_shndx ];
212
214
const alignment = @max (1 , shdr .sh_addralign );
213
215
return if (s_sym .st_value == 0 )
@@ -229,11 +231,8 @@ const AddExtraOpts = struct {
229
231
subsection : ? u32 = null ,
230
232
};
231
233
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 ).? ;
234
+ pub fn addExtra (symbol : * Symbol , opts : AddExtraOpts , elf_file : * Elf ) void {
235
+ var extra = symbol .getExtra (elf_file );
237
236
inline for (@typeInfo (@TypeOf (opts )).@"struct" .fields ) | field | {
238
237
if (@field (opts , field .name )) | x | {
239
238
@field (extra , field .name ) = x ;
@@ -242,17 +241,21 @@ pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {
242
241
symbol .setExtra (extra , elf_file );
243
242
}
244
243
245
- pub inline fn getExtra (symbol : Symbol , elf_file : * Elf ) ? Extra {
246
- return elf_file .getSymbolExtra (symbol .extra );
244
+ pub fn getExtra (symbol : Symbol , elf_file : * Elf ) Extra {
245
+ return switch (symbol .getFile (elf_file ).? ) {
246
+ inline else = > | x | x .getSymbolExtra (symbol .extra ),
247
+ };
247
248
}
248
249
249
- pub inline fn setExtra (symbol : Symbol , extra : Extra , elf_file : * Elf ) void {
250
- elf_file .setSymbolExtra (symbol .extra , extra );
250
+ pub fn setExtra (symbol : Symbol , extra : Extra , elf_file : * Elf ) void {
251
+ return switch (symbol .getFile (elf_file ).? ) {
252
+ inline else = > | x | x .setSymbolExtra (symbol .extra , extra ),
253
+ };
251
254
}
252
255
253
256
pub fn setOutputSym (symbol : Symbol , elf_file : * Elf , out : * elf.Elf64_Sym ) void {
254
257
const file = symbol .getFile (elf_file ).? ;
255
- const s_sym = symbol .getSourceSymbol (elf_file );
258
+ const s_sym = symbol .getElfSym (elf_file );
256
259
const st_type = symbol .getType (elf_file );
257
260
const st_bind : u8 = blk : {
258
261
if (symbol .isLocal (elf_file )) break :blk 0 ;
@@ -347,10 +350,10 @@ fn format2(
347
350
_ = options ;
348
351
_ = unused_fmt_string ;
349
352
const symbol = ctx .symbol ;
350
- try writer .print ("%{d} : {s} : @{x}" , .{ symbol .sym_idx , symbol .fmtName (ctx .elf_file ), symbol .getAddress (.{}, ctx .elf_file ) });
353
+ try writer .print ("%{d} : {s} : @{x}" , .{ symbol .esym_idx , symbol .fmtName (ctx .elf_file ), symbol .getAddress (.{}, ctx .elf_file ) });
351
354
if (symbol .getFile (ctx .elf_file )) | file | {
352
355
if (symbol .isAbs (ctx .elf_file )) {
353
- if (symbol .getSourceSymbol (ctx .elf_file ).st_shndx == elf .SHN_UNDEF ) {
356
+ if (symbol .getElfSym (ctx .elf_file ).st_shndx == elf .SHN_UNDEF ) {
354
357
try writer .writeAll (" : undef" );
355
358
} else {
356
359
try writer .writeAll (" : absolute" );
0 commit comments