[all-commits] [llvm/llvm-project] e13a8a: [MC][COFF][ELF] Reject instructions in IMAGE_SCN_C...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Apr 15 21:03:09 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: e13a8a1fc56837e2f21b85b89a445fb4f21500d6
      https://github.com/llvm/llvm-project/commit/e13a8a1fc56837e2f21b85b89a445fb4f21500d6
  Author: Fangrui Song <maskray at google.com>
  Date:   2020-04-15 (Wed, 15 Apr 2020)

  Changed paths:
    M llvm/include/llvm/MC/MCSection.h
    M llvm/include/llvm/MC/MCSectionCOFF.h
    M llvm/include/llvm/MC/MCSectionELF.h
    M llvm/lib/MC/MCAssembler.cpp
    M llvm/lib/MC/MCObjectStreamer.cpp
    M llvm/lib/MC/MCSection.cpp
    M llvm/lib/MC/MCSectionCOFF.cpp
    M llvm/lib/MC/MCSectionELF.cpp
    A llvm/test/MC/COFF/bss-text.s
    R llvm/test/MC/ELF/ARM/bss-non-zero-value.s
    A llvm/test/MC/ELF/nobits-non-zero-value.s
    R llvm/test/MC/X86/reloc-bss.s

  Log Message:
  -----------
  [MC][COFF][ELF] Reject instructions in IMAGE_SCN_CNT_UNINITIALIZED_DATA/SHT_NOBITS sections

For `.bss; nop`, MC inappropriately calls abort() (via report_fatal_error()) with a message
`cannot have fixups in virtual section!`
It is a bug to crash for invalid user input. Fix it by erroring out early in EmitInstToData().

Similarly, emitIntValue() in a virtual section (SHT_NOBITS in ELF) can crash with the mssage
`non-zero initializer found in section '.bss'` (see D4199)
It'd be nice to report the location but so many directives can call emitIntValue()
and it is difficult to track every location.
Note, COFF does not crash because MCAssembler::writeSectionData() is not
called for an IMAGE_SCN_CNT_UNINITIALIZED_DATA section.

Note, GNU as' arm64 backend reports ``Error: attempt to store non-zero value in section `.bss'``
for a non-zero .inst but fails to do so for other instructions.
We simply reject all instructions, even if the encoding is all zeros.

The Mach-O counterpart is D48517 (see `test/MC/MachO/zerofill-text.s`)

Reviewed By: rnk, skan

Differential Revision: https://reviews.llvm.org/D78138




More information about the All-commits mailing list