Skip to content

Conversation

@Lichtso
Copy link
Collaborator

@Lichtso Lichtso commented Nov 6, 2025

  • Adjusts the e_machine to EM_BPF
  • Ignores the e_type
  • Removes the stack and heap program headers
  • Reorders the bytecode and rodata program headers

@Lichtso Lichtso force-pushed the feature/adjustments_of_simd_0189 branch 2 times, most recently from f72af30 to f8a44d5 Compare November 6, 2025 12:45
@LucasSte LucasSte self-requested a review November 6, 2025 19:59
src/elf.rs Outdated
|| program_header.p_paddr != *p_vaddr
|| program_header.p_filesz != p_filesz
|| program_header.p_vaddr != p_vaddr
|| program_header.p_paddr != p_vaddr
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this relevant for us? p_addr is the physical address, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not change anything about p_addr in this PR, just removed the deref.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just wondering if we shouldn't disregard this field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless there is tooling which likes to emit this value differently I would say we pin as much as we can.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think there is any problem there. Those fields are controlled by the linker script. If they are working now, they will continue working with the new layout, I believe.

. = ALIGN(8);
} :rodata
.text 0x100000000 : {
*(.text*)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to do it here, but if you want, you can remove the .bss.stack and .bss.heap from the linker script.

(),
TestContextObject::new(3),
ProgramResult::Ok(ebpf::MM_BYTECODE_START),
ProgramResult::Ok(ebpf::MM_RODATA_START),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The address of the entrypoint is MM_BYTECODE_START, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Jup, see answer for the other test.

TestContextObject::new(4),
ProgramResult::Ok(ebpf::MM_RODATA_START),
TestContextObject::new(3),
ProgramResult::Ok(ebpf::MM_BYTECODE_START),
Copy link
Collaborator

Choose a reason for hiding this comment

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

All these tests are returning the inverted addresses, aren't they?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is because I did not change the constants naming in this PR. And that again has to do with the AlignedMemory mapping rejecting a region at address 0. We can fix that once we enable account data direct mapping any only use the UnalignedMemory mapping in production.

If you want I can put the numeric values here to avoid confusion in the meantime.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To make tests comprehensive, you could just compare with the number itself and add a comment next to it explaining what section that number refers to in the v3 organization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I rebased the PR ontop of the changes which allow us to now swap / rename these two constants.

@Lichtso Lichtso force-pushed the feature/adjustments_of_simd_0189 branch from f8a44d5 to 526b717 Compare November 18, 2025 16:12
src/elf.rs Outdated
text_section_vaddr: if sbpf_version.enable_lower_bytecode_vaddr() {
ebpf::MM_BYTECODE_START
} else {
ro_section: Section::Borrowed(ebpf::MM_BYTECODE_START as usize, 0..text_bytes.len()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be MM_RODATA_START for v3?

src/elf.rs Outdated
Comment on lines 360 to 363
text_section_vaddr: if sbpf_version.enable_lower_rodata_vaddr() {
ebpf::MM_RODATA_START
} else {
ebpf::MM_BYTECODE_START
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, enable_lower_rodata_vaddr returns true for a version greater than v3, but you are saying that the text section vaddr is MM_RODATA_START. Shouldn't this if be inverted?

@Lichtso Lichtso force-pushed the feature/adjustments_of_simd_0189 branch 2 times, most recently from e277dab to a898615 Compare November 24, 2025 09:45
@Lichtso Lichtso force-pushed the feature/adjustments_of_simd_0189 branch from a898615 to 8e313a0 Compare November 24, 2025 15:22
Comment on lines +207 to +208
let region_name = match vm_addr & (!ebpf::MM_BYTECODE_START.saturating_sub(1)) {
ebpf::MM_BYTECODE_START => "program",

Choose a reason for hiding this comment

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

Should we include another match arm in here for ebpf::MM_RODATA_START?

We could treat both as "program", like we do in < SBPF v3, or we could have "bytecode" and "rodata" messages. Seems probably useful to distinguish between the two, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

We didn't merge that PR yet, because we have not yet finalized the ABIv2 design.

Choose a reason for hiding this comment

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

Ah okay, thanks. Does it hurt to add the "rodata" arm here though?

@Lichtso Lichtso requested a review from LucasSte November 26, 2025 17:58
if program_header.p_type != PT_LOAD
|| program_header.p_flags != *p_flags
|| program_header.p_offset < program_header_table_range.end as u64
|| program_header.p_offset != expected_offset
Copy link
Collaborator

Choose a reason for hiding this comment

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

This restriction is not guaranteed to work. I tested it here and LLD does not output it automatically. In one of the cases, I could only get it once I called llvm-objcopy --strip-all. I suggest reverting it to the original restriction.

Copy link
Collaborator

Choose a reason for hiding this comment

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

llvm-objcopy --strip-all does not work with enable_symbol_and_section_labels set to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants