Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write/elf: add Writer::reserve_null_symbol_index #402

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<'a> Object<'a> {

// Calculate index of symbols and add symbol strings to strtab.
let mut symbol_offsets = vec![SymbolOffsets::default(); self.symbols.len()];
writer.reserve_null_symbol_index();
// Local symbols must come before global.
for (index, symbol) in self.symbols.iter().enumerate() {
if symbol.is_local() {
Expand Down
17 changes: 17 additions & 0 deletions src/write/elf/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,23 @@ impl<'a> Writer<'a> {
});
}

/// Reserve the null symbol table entry.
///
/// This will be stored in the `.symtab` section.
///
/// The null symbol table entry is usually automatically reserved,
/// but this can be used to force an empty symbol table.
///
/// This must be called before [`Self::reserve_symtab`].
pub fn reserve_null_symbol_index(&mut self) -> SymbolIndex {
debug_assert_eq!(self.symtab_offset, 0);
debug_assert_eq!(self.symtab_num, 0);
self.symtab_num = 1;
// The symtab must link to a strtab.
self.need_strtab = true;
SymbolIndex(0)
}

/// Reserve a symbol table entry.
///
/// This will be stored in the `.symtab` section.
Expand Down