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

Sections containing instructions should be aligned to the architecture's instruction alignment #117103

Open
pcc opened this issue Nov 21, 2024 · 4 comments

Comments

@pcc
Copy link
Contributor

pcc commented Nov 21, 2024

When assembling the following for AArch64:

        .section        .text.unlikely,"ax",@progbits
.Ltmp4:
        b       .Ltmp4

LLVM's section headers:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .strtab           STRTAB          0000000000000000 000078 000029 00      0   0  1
  [ 2] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  4
  [ 3] .text.unlikely    PROGBITS        0000000000000000 000040 000004 00  AX  0   0  1
  [ 4] .symtab           SYMTAB          0000000000000000 000048 000030 18      1   2  8

GNU as section headers:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  1
  [ 2] .data             PROGBITS        0000000000000000 000040 000000 00  WA  0   0  1
  [ 3] .bss              NOBITS          0000000000000000 000040 000000 00  WA  0   0  1
  [ 4] .text.unlikely    PROGBITS        0000000000000000 000040 000004 00  AX  0   0  4
  [ 5] .symtab           SYMTAB          0000000000000000 000048 000090 18      6   6  8
  [ 6] .strtab           STRTAB          0000000000000000 0000d8 000004 00      0   0  1
  [ 7] .shstrtab         STRTAB          0000000000000000 0000dc 00003b 00      0   0  1

As a result of the LLVM behavior, we can end up misaligning the .text.unlikely section (e.g. if a preceding section contains data of size not a multiple of 4) and causing a crash at runtime.

I think the GNU as behavior makes more sense, and we should adopt that behavior.

@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/issue-subscribers-backend-aarch64

Author: None (pcc)

When assembling the following for AArch64: ``` .section .text.unlikely,"ax",@progbits .Ltmp4: b .Ltmp4 ``` LLVM's section headers: ``` Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .strtab STRTAB 0000000000000000 000078 000029 00 0 0 1 [ 2] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 4 [ 3] .text.unlikely PROGBITS 0000000000000000 000040 000004 00 AX 0 0 1 [ 4] .symtab SYMTAB 0000000000000000 000048 000030 18 1 2 8 ``` GNU as section headers: ``` Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000000000 000040 000000 00 AX 0 0 1 [ 2] .data PROGBITS 0000000000000000 000040 000000 00 WA 0 0 1 [ 3] .bss NOBITS 0000000000000000 000040 000000 00 WA 0 0 1 [ 4] .text.unlikely PROGBITS 0000000000000000 000040 000004 00 AX 0 0 4 [ 5] .symtab SYMTAB 0000000000000000 000048 000090 18 6 6 8 [ 6] .strtab STRTAB 0000000000000000 0000d8 000004 00 0 0 1 [ 7] .shstrtab STRTAB 0000000000000000 0000dc 00003b 00 0 0 1 ``` As a result of the LLVM behavior, we can end up misaligning the `.text.unlikely` section (e.g. if a preceding section contains data of size not a multiple of 4) and causing a crash at runtime.

I think the GNU as behavior makes more sense, and we should adopt that behavior.

@efriedma-quic
Copy link
Collaborator

See also #90358 . (Not a duplicate, though.)

@lenary
Copy link
Member

lenary commented Nov 21, 2024

I think that #114031 will fix this? Sorry for dropping the ball on finishing that review.

@lenary
Copy link
Member

lenary commented Nov 21, 2024

Ah, sorry, that fix is just aarch64, but you want this for all architectures.

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

No branches or pull requests

5 participants