Skip to content

Commit

Permalink
elf: fix Symbol.isAbs() for symbols belonging to internal object file
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 10, 2023
1 parent 1b239f3 commit 685ca12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/Elf/Atom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,15 @@ inline fn checkTextReloc(self: Atom, symbol: *const Symbol, elf_file: *Elf) void
const is_writeable = self.getInputShdr(elf_file).sh_flags & elf.SHF_WRITE != 0;
if (!is_writeable) {
if (elf_file.options.z_text) {
elf_file.base.fatal("{s}: relocation against symbol '{s}' in read-only section", .{
elf_file.base.fatal("{s}: {s}: relocation against symbol '{s}' in read-only section", .{
self.getObject(elf_file).fmtPath(),
self.getName(elf_file),
symbol.getName(elf_file),
});
} else {
// TODO
elf_file.base.fatal("{s}: TODO handle relocations in read-only section", .{
elf_file.base.fatal("{s}: {s}: TODO handle relocations in read-only section", .{
self.getObject(elf_file).fmtPath(),
self.getName(elf_file),
});
}
Expand All @@ -348,7 +350,8 @@ inline fn unhandledRelocError(
action: RelocAction,
elf_file: *Elf,
) void {
elf_file.base.fatal("{s}: unhandled {} relocation at offset 0x{x} against symbol '{s}': action {s}", .{
elf_file.base.fatal("{s}: {s}: unhandled {} relocation at offset 0x{x} against symbol '{s}': action {s}", .{
self.getObject(elf_file).fmtPath(),
self.getName(elf_file),
fmtRelocType(rel.r_type()),
rel.r_offset,
Expand All @@ -359,8 +362,9 @@ inline fn unhandledRelocError(

inline fn noPicError(self: Atom, symbol: *const Symbol, rel: elf.Elf64_Rela, elf_file: *Elf) void {
elf_file.base.fatal(
"{s}: {} relocation at offset 0x{x} against symbol '{s}' cannot be used; recompile with -fno-PIC",
"{s}: {s}: {} relocation at offset 0x{x} against symbol '{s}' cannot be used; recompile with -fno-PIC",
.{
self.getObject(elf_file).fmtPath(),
self.getName(elf_file),
fmtRelocType(rel.r_type()),
rel.r_offset,
Expand All @@ -371,8 +375,9 @@ inline fn noPicError(self: Atom, symbol: *const Symbol, rel: elf.Elf64_Rela, elf

inline fn picError(self: Atom, symbol: *const Symbol, rel: elf.Elf64_Rela, elf_file: *Elf) void {
elf_file.base.fatal(
"{s}: {} relocation at offset 0x{x} against symbol '{s}' cannot be used; recompile with -fPIC",
"{s}: {s}: {} relocation at offset 0x{x} against symbol '{s}' cannot be used; recompile with -fPIC",
.{
self.getObject(elf_file).fmtPath(),
self.getName(elf_file),
fmtRelocType(rel.r_type()),
rel.r_offset,
Expand Down
3 changes: 3 additions & 0 deletions src/Elf/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const usage =
\\--dynamic Alias for --Bdynamic
\\--dynamic-linker=[value], -I [value]
\\ Set the dynamic linker to use
\\--no-dynamic-linker Don't set the dynamic linker
\\--end-group Ignored for compatibility with GNU
\\--eh-frame-hdr Create .eh_frame_hdr section (default)
\\--export-dynamic, -E Export all dynamic symbols
Expand Down Expand Up @@ -212,6 +213,8 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options
try positionals.append(.{ .tag = .pop_state });
} else if (p.argAny("dynamic-linker")) |path| {
opts.dynamic_linker = path;
} else if (p.flagAny("no-dynamic-linker")) {
opts.dynamic_linker = null;
} else if (p.arg1("I")) |path| {
opts.dynamic_linker = path;
} else if (p.flagAny("eh-frame-hdr")) {
Expand Down
6 changes: 2 additions & 4 deletions src/Elf/Symbol.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ extra: u32 = 0,

pub fn isAbs(symbol: Symbol, elf_file: *Elf) bool {
const file = symbol.getFile(elf_file).?;
if (file == .shared)
return symbol.getSourceSymbol(elf_file).st_shndx == elf.SHN_ABS;

return !symbol.flags.import and symbol.getAtom(elf_file) == null and symbol.shndx == 0;
if (file == .shared) return symbol.getSourceSymbol(elf_file).st_shndx == elf.SHN_ABS;
return !symbol.flags.import and symbol.getAtom(elf_file) == null and symbol.shndx == 0 and file != .internal;
}

pub fn isLocal(symbol: Symbol) bool {
Expand Down

0 comments on commit 685ca12

Please sign in to comment.