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

lld/ELF: Report errors for certain unknown section types #84812

Closed
MaskRay opened this issue Mar 11, 2024 · 1 comment · Fixed by #85173
Closed

lld/ELF: Report errors for certain unknown section types #84812

MaskRay opened this issue Mar 11, 2024 · 1 comment · Fixed by #85173
Assignees
Labels

Comments

@MaskRay
Copy link
Member

MaskRay commented Mar 11, 2024

From https://maskray.me/blog/2024-03-09-a-compact-relocation-format-for-elf#linker-notes

GNU ld allows certain unknown section types:

  • [SHT_LOUSER,SHT_HIUSER] and non-SHF_ALLOC
  • [SHT_LOOS,SHT_HIOS] and non-SHF_OS_NONCONFORMING

but reports errors and stops linking for others (unless --no-warn-mismatch is specified).
When linking a relocatable file using SHT_RELLEB, you might encounter errors like the following:

% myclang -mrelleb -fuse-ld=bfd a.c b.c
/usr/bin/ld.bfd: unknown architecture of input file `/tmp/a-1e0778.o' is incompatible with i386:x86-64 output
/usr/bin/ld.bfd: unknown architecture of input file `/tmp/b-9963f0.o' is incompatible with i386:x86-64 output
/usr/bin/ld.bfd: error in /tmp/a-1e0778.o(.eh_frame); no .eh_frame_hdr table will be created
/usr/bin/ld.bfd: error in /tmp/b-9963f0.o(.eh_frame); no .eh_frame_hdr table will be created
clang: error: linker command failed with exit code 1 (use -v to see invocation)
% myclang -mrelleb -fuse-ld=bfd a.c b.c -Wl,--no-warn-mismatch && ./a.out
/usr/bin/ld.bfd: error in /tmp/a-a1a5f4.o(.eh_frame); no .eh_frame_hdr table will be created
/usr/bin/ld.bfd: error in /tmp/b-9dd23c.o(.eh_frame); no .eh_frame_hdr table will be created
[1]    2459175 segmentation fault  ./a.out

I have a prototype for a new relocation format (RELLEB). Linking a.o and b.o with unpatched lld and gold create an output file with unrelocated .text and will crash at run-time.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 11, 2024

@llvm/issue-subscribers-lld-elf

Author: Fangrui Song (MaskRay)

From https://maskray.me/blog/2024-03-09-a-compact-relocation-format-for-elf#linker-notes

GNU ld allows certain unknown section types:

  • [SHT_LOUSER,SHT_HIUSER] and non-SHF_ALLOC
  • [SHT_LOOS,SHT_HIOS] and non-SHF_OS_NONCONFORMING

but reports errors and stops linking for others (unless --no-warn-mismatch is specified).
When linking a relocatable file using SHT_RELLEB, you might encounter errors like the following:

% clang -mrelleb -fuse-ld=bfd a.c b.c
/usr/bin/ld.bfd: unknown architecture of input file `/tmp/a-1e0778.o' is incompatible with i386:x86-64 output
/usr/bin/ld.bfd: unknown architecture of input file `/tmp/b-9963f0.o' is incompatible with i386:x86-64 output
/usr/bin/ld.bfd: error in /tmp/a-1e0778.o(.eh_frame); no .eh_frame_hdr table will be created
/usr/bin/ld.bfd: error in /tmp/b-9963f0.o(.eh_frame); no .eh_frame_hdr table will be created
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have a prototype for a new relocation format (RELLEB). Linking a.o and b.o with unpatched lld and gold create an output file with unrelocated .text and will crash at run-time.

@MaskRay MaskRay self-assigned this Mar 11, 2024
MaskRay added a commit that referenced this issue Mar 15, 2024
Unknown section sections may require special linking rules, and
rejecting such sections for older linkers may be desired. For example,
if we introduce a new section type to replace a control structure (e.g.
relocations), it would be nice for older linkers to reject the new
section type. GNU ld allows certain unknown section types:

* [SHT_LOUSER,SHT_HIUSER] and non-SHF_ALLOC
* [SHT_LOOS,SHT_HIOS] and non-SHF_OS_NONCONFORMING

but reports errors and stops linking for others (unless
--no-warn-mismatch is specified). Port its behavior. For convenience, we
additionally allow all [SHT_LOPROC,SHT_HIPROC] types so that we don't
have to hard code all known types for each processor.

Close #84812
ilovepi pushed a commit to ilovepi/llvm-project that referenced this issue Mar 15, 2024
Unknown section sections may require special linking rules, and
rejecting such sections for older linkers may be desired. For example,
if we introduce a new section type to replace a control structure (e.g.
relocations), it would be nice for older linkers to reject the new
section type. GNU ld allows certain unknown section types:

* [SHT_LOUSER,SHT_HIUSER] and non-SHF_ALLOC
* [SHT_LOOS,SHT_HIOS] and non-SHF_OS_NONCONFORMING

but reports errors and stops linking for others (unless
--no-warn-mismatch is specified). Port its behavior. For convenience, we
additionally allow all [SHT_LOPROC,SHT_HIPROC] types so that we don't
have to hard code all known types for each processor.

Close llvm#84812
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants