Skip to content

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

@pcc

Description

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions