1. Feb 13, 2020
    • Fangrui Song's avatar
      [ELF] Start a new PT_LOAD if LMA region is different · b498d993
      Fangrui Song authored
      GNU ld has a counterintuitive lang_propagate_lma_regions rule.
      
      ```
      // .foo's LMA region is propagated to .bar because their VMA region is the same,
      // and .bar does not have an explicit output section address (addr_tree).
      .foo : { *(.foo) } >RAM AT> FLASH
      .bar : { *(.bar) } >RAM
      
      // An explicit output section address disables propagation.
      .foo : { *(.foo) } >RAM AT> FLASH
      .bar . : { *(.bar) } >RAM
      ```
      
      In both cases, lld thinks .foo's LMA region is propagated and
      places .bar in the same PT_LOAD, so lld diverges from GNU ld w.r.t. the
      second case (lma-align.test).
      
      This patch changes Writer<ELFT>::createPhdrs to disable propagation
      (start a new PT_LOAD). A user of the first case can make linker scripts
      portable by explicitly specifying `AT>`. By contrast, there was no
      workaround for the old behavior.
      
      This change uncovers another LMA related bug in assignOffsets() where
      `ctx->lmaOffset = 0;` was omitted. It caused a spurious "load address
      range overlaps" error for at2.test
      
      The new PT_LOAD rule is complex. For convenience, I listed the origins of some subexpressions:
      
      * rL323449: `sec->memRegion == load->firstSec->memRegion`; linkerscript/at3.test
      * D43284: `load->lastSec == Out::programHeaders` (don't start a new PT_LOAD after program headers); linkerscript/at4.test
      * D58892: `sec != relroEnd` (start a new PT_LOAD after PT_GNU_RELRO)
      
      Reviewed By: psmith
      
      Differential Revision: https://reviews.llvm.org/D74297
      b498d993
    • Fangrui Song's avatar
      [ELF] Respect output section alignment for AT> (non-null lmaRegion) · e21b9ca7
      Fangrui Song authored
      When lmaRegion is non-null, respect `sec->alignment`
      This rule is analogous to `switchTo(sec)` which advances sh_addr (VMA).
      
      This fixes the p_paddr misalignment issue as reported by
      https://android-review.googlesource.com/c/trusty/external/trusted-firmware-a/+/1230058
      
      Note, `sec->alignment` is the maximum of ALIGN and input section alignments. We may overalign LMA than GNU ld.
      
      linkerscript/align-lma.s has a FIXME that demonstrates another bug:
      `.bss ... >RAM` should be placed in a different PT_LOAD (GNU ld
      behavior) because its lmaRegion (nullptr) is different from the previous
      section's lmaRegion (ROM).
      
      Reviewed By: psmith
      
      Differential Revision: https://reviews.llvm.org/D74286
      e21b9ca7
    • Jordan Rupprecht's avatar
      [llvm-objdump] Print file format in lowercase to match GNU output. · 60a8a504
      Jordan Rupprecht authored
      Summary:
      GNU objdump prints the file format in lowercase, e.g. `elf64-x86-64`. llvm-objdump prints `ELF64-x86-64` right now, even though piping that into llvm-objcopy refuses that as a valid arch to use.
      
      As an example of a problem this causes, see: https://github.com/ClangBuiltLinux/linux/issues/779
      
      Reviewers: MaskRay, jhenderson, alexshap
      
      Reviewed By: MaskRay
      
      Subscribers: tpimh, sbc100, grimar, jvesely, nhaehnle, kerbowa, cfe-commits, llvm-commits
      
      Tags: #clang, #llvm
      
      Differential Revision: https://reviews.llvm.org/D74433
      60a8a504
    • Simon Pilgrim's avatar
      [X86] combineFneg - generalize FMA negations with isNegatibleForFree/getNegatedExpression · ff307c81
      Simon Pilgrim authored
      This has a really interesting side effect in that it improves some UMAX/UMIN reduction code which had redundant XOR(SHUFFLE(XOR(X,SIGNMASK)),SIGNMASK) patterns - the getNegatibleCost recognises it as FNEG(SHUFFLE(FNEG(X))).... We have a lot of FNEG patterns bitcasted to the integer domain for XOR signbit twiddling which is similar to what we do to allow UMAX/UMIN to be lowered using SMAX/SMIN.
      
      Differential Revision: https://reviews.llvm.org/D74231
      ff307c81
  2. Feb 12, 2020