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

Discern ELF targeting eBPF for Windows from ones targeting Linux #3956

Open
lmb opened this issue Oct 27, 2024 · 1 comment
Open

Discern ELF targeting eBPF for Windows from ones targeting Linux #3956

lmb opened this issue Oct 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request P2 triaged Discussed in a triage meeting
Milestone

Comments

@lmb
Copy link
Collaborator

lmb commented Oct 27, 2024

Describe the feature you'd like supported

Right now it is not possible to determine the target platform from the contents of an ELF. A program compiled against Linux headers looks the same as a programs compiled against Windows ones. This is a problem for projects which need to support loading ELF from both platforms because while the ELF are superficially similar the contents aren't compatible:

There should be a way for toolchains to figure out the platform of an ELF.

Proposed solution

  1. Add a new ELF section similar to .license which contains a string that indicates the platform, e.g. windows or linux.
  2. Somehow set the ELF OS/ABI field to something meaningful.
    $ readelf -h testdata/loader-clang-el.elf 
    ELF Header:
      Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
      Class:                             ELF64
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
    

It would be best if this was coordinated with upstream libbpf somehow.

Additional context

No response

@lmb lmb added the enhancement New feature or request label Oct 27, 2024
@lmb lmb changed the title Make it possible to discern ELF targeting eBPF for Windows from ones targeting Linux Discern ELF targeting eBPF for Windows from ones targeting Linux Oct 27, 2024
@shankarseal shankarseal added triaged Discussed in a triage meeting P2 labels Oct 28, 2024
@shankarseal shankarseal added this to the 2411 milestone Oct 28, 2024
@lmb
Copy link
Collaborator Author

lmb commented Oct 28, 2024

I'll send a PR which adds a temporary workaround to one of the headers in this project. I won't do the upstream discussion how to make this cross platform.

lmb added a commit to isovalent/ebpf-for-windows that referenced this issue Oct 30, 2024
Compiling against Windows eBPF headers produces object files which are not easily
distinguishable from object files compiled against Linux headers. This is a problem
for cross-platform tooling which wishes to inspect the contents of an ELF.

Emit a section .ebpf_for_windows with the contents 0x01 into ELFs compiled against
the windows headers.

Updates microsoft#3956
lmb added a commit to isovalent/ebpf-for-windows that referenced this issue Nov 1, 2024
Compiling against Windows eBPF headers produces object files which are not easily
distinguishable from object files compiled against Linux headers. This is a problem
for cross-platform tooling which wishes to inspect the contents of an ELF.

Emit a section .ebpf_for_windows with the contents 0x01 into ELFs compiled against
the windows headers.

Updates microsoft#3956
@shankarseal shankarseal modified the milestones: 2411, 2501 Nov 2, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 5, 2024
Compiling against Windows eBPF headers produces object files which are not easily
distinguishable from object files compiled against Linux headers. This is a problem
for cross-platform tooling which wishes to inspect the contents of an ELF.

Emit a section .ebpf_for_windows with the contents 0x01 into ELFs compiled against
the windows headers.

Updates #3956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 triaged Discussed in a triage meeting
Projects
None yet
Development

No branches or pull requests

2 participants