[PATCH] D74286: [ELF] Respect output section alignment for AT> (non-null lmaRegion)

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 04:05:23 PST 2020


psmith added a comment.

OK, to check my understanding. Tracing through that bit of BFD code it seems like in the absence of ALIGN_WITH_INPUT the VMA is aligned to the OutputSection alignment when:

- `(os->addr_tree) // output_section_address is specified`
- `if (os->lma_region != os->region) section_alignment = exp_get_power (os->section_alignment, "section alignment");`

In all other cases it uses the max of input section alignment. With ALIGN_WITH_INPUT we force the use of dotdelta, which is align by the same alignment as the dot got aligned. I think that this is subtly different to the section alignment as the VMA and LMA could start from different bases.

For LLD we are using the max of input_section_alignment and output section alignment. Which aligns more than bfd, as there is a possibility in bfd that output section alignment is lower than the max of input section alignment. For example running the test case using ld.bfd using arm-none-eabi-ld (only one I had on the machine so I had to replace ret with a 4-byte sized arm instruction).

  LOAD           0x000000 0x00000000 0x00000000 0x01004 0x01004 R E 0x10000
  LOAD           0x011000 0x00011000 0x00001004 0x00001 0x00001 RW  0x10000
  LOAD           0x011010 0x00011010 0x00001010 0x00001 0x00001 RW  0x10000
  LOAD           0x011040 0x00011040 0x00011040 0x00000 0x00001 RW  0x10000

Note that .data.rel.ro despite having an alignment of 16, hasn't had the LMA aligned. This could matter to some embedded systems people wanting to squeeze every last byte out of a tiny microcontroller's flash, but not likely to be a problem for the firmware on something that is booting linux. My concern is that if we adopt the strict behaviour it will be difficult to go back without breaking existing linker scripts.

One argument that we can change this in the future is that the vast majority of embedded projects use ld.bfd and will be used to its behaviour, so we can conform more tightly to it in the future.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74286/new/

https://reviews.llvm.org/D74286





More information about the llvm-commits mailing list