| ... | ... | @@ -356,52 +356,30 @@ pub const GotSection = struct { |
| 356 | 356 | // return num; |
| 357 | 357 | // } |
| 358 | 358 | |
| 359 | | pub fn calcSymtabSize(got: *GotSection, elf_file: *Elf) !void { |
| 360 | | got.output_symtab_size.nlocals = @as(u32, @intCast(got.symbols.items.len)); |
| 361 | | for (got.symbols.items) |sym| { |
| 362 | | const suffix_len = switch (sym) { |
| 363 | | .tlsgd => "$tlsgd".len, |
| 364 | | .got => "$got".len, |
| 365 | | .gottp => "$gottp".len, |
| 366 | | .tlsdesc => "$tlsdesc".len, |
| 367 | | }; |
| 368 | | const symbol = elf_file.getSymbol(sym.getIndex()); |
| 369 | | const name_len = symbol.getName(elf_file).len; |
| 370 | | got.output_symtab_size.strsize += @as(u32, @intCast(name_len + suffix_len + 1)); |
| 371 | | } |
| 372 | | |
| 373 | | if (got.emit_tlsld) { |
| 374 | | got.output_symtab_size.nlocals += 1; |
| 375 | | got.output_symtab_size.strsize += @as(u32, @intCast("$tlsld".len + 1)); |
| 376 | | } |
| 359 | pub fn updateSymtabSize(got: *GotSection, elf_file: *Elf) void { |
| 360 | _ = elf_file; |
| 361 | got.output_symtab_size.nlocals = @as(u32, @intCast(got.entries.items.len)); |
| 377 | 362 | } |
| 378 | 363 | |
| 379 | 364 | pub fn writeSymtab(got: GotSection, elf_file: *Elf, ctx: anytype) !void { |
| 380 | 365 | const gpa = elf_file.base.allocator; |
| 381 | | |
| 382 | | var ilocal = ctx.ilocal; |
| 383 | | for (got.symbols.items) |sym| { |
| 384 | | const suffix = switch (sym) { |
| 366 | for (got.entries.items, ctx.ilocal..) |entry, ilocal| { |
| 367 | const suffix = switch (entry.tag) { |
| 368 | .tlsld => "$tlsld", |
| 385 | 369 | .tlsgd => "$tlsgd", |
| 386 | 370 | .got => "$got", |
| 387 | 371 | .gottp => "$gottp", |
| 388 | 372 | .tlsdesc => "$tlsdesc", |
| 389 | 373 | }; |
| 390 | | const symbol = elf_file.getSymbol(sym.getIndex()); |
| 391 | | const name = try std.fmt.allocPrint(gpa, "{s}{s}", .{ symbol.getName(elf_file), suffix }); |
| 374 | const symbol = elf_file.symbol(entry.symbol_index); |
| 375 | const name = try std.fmt.allocPrint(gpa, "{s}{s}", .{ symbol.name(elf_file), suffix }); |
| 392 | 376 | defer gpa.free(name); |
| 393 | | const st_name = try ctx.strtab.insert(gpa, name); |
| 394 | | const st_value = switch (sym) { |
| 395 | | // .tlsgd => symbol.tlsGdAddress(elf_file), |
| 377 | const st_name = try elf_file.strtab.insert(gpa, name); |
| 378 | const st_value = switch (entry.tag) { |
| 396 | 379 | .got => symbol.gotAddress(elf_file), |
| 397 | | // .gottp => symbol.gotTpAddress(elf_file), |
| 398 | | // .tlsdesc => symbol.tlsDescAddress(elf_file), |
| 399 | 380 | else => unreachable, |
| 400 | 381 | }; |
| 401 | | const st_size: u64 = switch (sym) { |
| 402 | | .tlsgd, .tlsdesc => 16, |
| 403 | | .got, .gottp => 8, |
| 404 | | }; |
| 382 | const st_size: u64 = entry.len() * elf_file.archPtrWidthBytes(); |
| 405 | 383 | ctx.symtab[ilocal] = .{ |
| 406 | 384 | .st_name = st_name, |
| 407 | 385 | .st_info = elf.STT_OBJECT, |
| ... | ... | @@ -410,21 +388,7 @@ pub const GotSection = struct { |
| 410 | 388 | .st_value = st_value, |
| 411 | 389 | .st_size = st_size, |
| 412 | 390 | }; |
| 413 | | ilocal += 1; |
| 414 | 391 | } |
| 415 | | |
| 416 | | // if (got.emit_tlsld) { |
| 417 | | // const st_name = try ctx.strtab.insert(gpa, "$tlsld"); |
| 418 | | // ctx.symtab[ilocal] = .{ |
| 419 | | // .st_name = st_name, |
| 420 | | // .st_info = elf.STT_OBJECT, |
| 421 | | // .st_other = 0, |
| 422 | | // .st_shndx = elf_file.got_sect_index.?, |
| 423 | | // .st_value = elf_file.getTlsLdAddress(), |
| 424 | | // .st_size = 16, |
| 425 | | // }; |
| 426 | | // ilocal += 1; |
| 427 | | // } |
| 428 | 392 | } |
| 429 | 393 | |
| 430 | 394 | const FormatCtx = struct { |