Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions libwild/src/elf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use crate::layout::SymbolCopyInfo;
use crate::layout::VersionDef;
use crate::layout::compute_allocations;
use crate::output_section_id;
use crate::output_section_id::EXECUTABLE_START;
use crate::output_section_id::OrderEvent;
use crate::output_section_id::OutputOrder;
use crate::output_section_id::OutputSectionId;
Expand Down Expand Up @@ -3124,6 +3125,9 @@ fn write_internal_symbols(
// __global_pointer$ = MIN(__SDATA_BEGIN__ + 0x800, MAX(__DATA_BEGIN__ + 0x800, __BSS_END__ - 0x800));
if symbol_name.bytes() == GLOBAL_POINTER_SYMBOL_NAME.as_bytes() {
address += RISCV_TLS_DTV_OFFSET;
} else if symbol_name.bytes() == EXECUTABLE_START.as_bytes() {
let text_layout = layout.section_layouts.get(output_section_id::TEXT);
address = text_layout.mem_offset;
}

let entry = symbol_writer
Expand Down
2 changes: 2 additions & 0 deletions libwild/src/output_section_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ const DEFAULT_DEFS: BuiltInSectionDetails = BuiltInSectionDetails {
target_segment_type: None,
};

pub(crate) const EXECUTABLE_START: &str = "__executable_start";
const SECTION_DEFINITIONS: [BuiltInSectionDetails; NUM_BUILT_IN_SECTIONS] = [
// A section into which we write headers.
BuiltInSectionDetails {
Expand Down Expand Up @@ -636,6 +637,7 @@ const SECTION_DEFINITIONS: [BuiltInSectionDetails; NUM_BUILT_IN_SECTIONS] = [
kind: SectionKind::Primary(SectionName(TEXT_SECTION_NAME)),
ty: sht::PROGBITS,
section_flags: shf::ALLOC.with(shf::EXECINSTR),
start_symbol_name: Some(EXECUTABLE_START),
..DEFAULT_DEFS
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong because that symbols should be emitted only for (some kinds of?) executables. Probably should be created inside Prelude::new.

Similarly, Wild outputs __ehdr_start even when other linkers don't, and it also misses __dso_handle symbol.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into this too much, but a couple of things that you were probably aware of, but just in case... some of these symbols are PROVIDE in the GNU ld linker script, which AFAIK means that the linker script should only define the symbol if it's referenced and not defined by anything input objects. We don't yet support PROVIDE semantics, although it might be being worked on - #1097.

Some flags can affect the built-in linker script that GNU ld uses. You can see what changes for some particular flag with a command like meld <(ld --verbose) <(ld --pie --verbose).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't see your comment when I was writing the other one (GitHub didn't refresh automatically). Well, I was unaware but figured that out eventually.

},
BuiltInSectionDetails {
Expand Down
Loading