[llvm] r241674 - [yaml2obj] Align section content using AddressAlign field's value

Kuba Brecka jbrecka at apple.com
Thu Jul 9 08:05:02 PDT 2015


After this commit, one of our internal bots fails these two tests:

Failing Tests (2):
   LLVM :: Object/Mips/elf-mips64-rel.yaml
   LLVM :: Object/yaml2obj-elf-symbol-basic.yaml

It looks like this is due to some wrongly assumed alignment, and some optimization is turning this into a crash only on this machine, while other buildbots seem to run fine.  I was able to reproduce the issue on my machine by adding the following assert (that explicitly checks the assumed alignment) into Support/Endian.h:

inline value_type read(const void *memory) {
  assert(((long)memory & ((detail::PickAlignment<value_type, alignment>::value)-1)) == 0);
  value_type ret;

  memcpy(&ret,
         LLVM_ASSUME_ALIGNED(memory,
           (detail::PickAlignment<value_type, alignment>::value)),
         sizeof(value_type));
  return byte_swap<value_type, endian>(ret);
}

Do you think you could take a look into that?

Thanks,
Kuba

> On 08 Jul 2015, at 12:12, Simon Atanasyan <simon at atanasyan.com> wrote:
> 
> Author: atanasyan
> Date: Wed Jul  8 05:12:40 2015
> New Revision: 241674
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=241674&view=rev
> Log:
> [yaml2obj] Align section content using AddressAlign field's value
> 
> Use AddressAlign field's value to properly align sections content in the
> yaml2obj tool. Before this change the yaml2obj ignored AddressAlign and
> always aligned section on 16 bytes boundary.
> 
> Added:
>    llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml
> Modified:
>    llvm/trunk/tools/yaml2obj/yaml2elf.cpp
> 
> Added: llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml?rev=241674&view=auto
> ==============================================================================
> --- llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml (added)
> +++ llvm/trunk/test/Object/yaml2obj-elf-alignment.yaml Wed Jul  8 05:12:40 2015
> @@ -0,0 +1,53 @@
> +# Check that yaml2obj takes in account section AddressAlign field.
> +
> +# RUN: yaml2obj -format=elf %s > %t
> +# RUN: llvm-readobj -s %t | FileCheck %s
> +
> +# CHECK:      Section {
> +# CHECK:        Index: 2
> +# CHECK-NEXT:   Name: .data
> +# CHECK-NEXT:   Type: SHT_PROGBITS
> +# CHECK-NEXT:   Flags [
> +# CHECK-NEXT:     SHF_ALLOC
> +# CHECK-NEXT:     SHF_WRITE
> +# CHECK-NEXT:   ]
> +# CHECK-NEXT:   Address: 0x0
> +# CHECK-NEXT:   Offset: 0x{{[0-9A-F]*}}00
> +# CHECK-NEXT:   Size: 4
> +# CHECK-NEXT:   Link: 0
> +# CHECK-NEXT:   Info: 0
> +# CHECK-NEXT:   AddressAlignment: 256
> +# CHECK-NEXT:   EntrySize: 0
> +# CHECK-NEXT: }
> +
> +---
> +FileHeader:
> +  Class:    ELFCLASS32
> +  Data:     ELFDATA2LSB
> +  Type:     ET_REL
> +  Machine:  EM_MIPS
> +  Flags:    [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
> +
> +Sections:
> +  - Name:          .text
> +    Type:          SHT_PROGBITS
> +    Flags:         [ SHF_ALLOC, SHF_EXECINSTR ]
> +    AddressAlign:  8
> +    Size:          4
> +  - Name:          .data
> +    Type:          SHT_PROGBITS
> +    Flags:         [ SHF_WRITE, SHF_ALLOC ]
> +    AddressAlign:  256
> +    Size:          4
> +
> +Symbols:
> +  Global:
> +    - Name:     T0
> +      Type:     STT_FUNC
> +      Section:  .text
> +      Size:     4
> +    - Name:     D0
> +      Type:     STT_OBJECT
> +      Section:  .data
> +      Size:     4
> +...
> 
> Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=241674&r1=241673&r2=241674&view=diff
> ==============================================================================
> --- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
> +++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Wed Jul  8 05:12:40 2015
> @@ -35,6 +35,8 @@ class ContiguousBlobAccumulator {
> 
>   /// \returns The new offset.
>   uint64_t padToAlignment(unsigned Align) {
> +    if (Align == 0)
> +      Align = 1;
>     uint64_t CurrentOffset = InitialOffset + OS.tell();
>     uint64_t AlignedOffset = RoundUpToAlignment(CurrentOffset, Align);
>     for (; CurrentOffset != AlignedOffset; ++CurrentOffset)
> @@ -46,7 +48,7 @@ public:
>   ContiguousBlobAccumulator(uint64_t InitialOffset_)
>       : InitialOffset(InitialOffset_), Buf(), OS(Buf) {}
>   template <class Integer>
> -  raw_ostream &getOSAndAlignedOffset(Integer &Offset, unsigned Align = 16) {
> +  raw_ostream &getOSAndAlignedOffset(Integer &Offset, unsigned Align) {
>     Offset = padToAlignment(Align);
>     return OS;
>   }
> @@ -246,7 +248,7 @@ bool ELFState<ELFT>::initSectionHeaders(
>       SHeader.sh_size = S->Size;
>       // SHT_NOBITS section does not have content
>       // so just to setup the section offset.
> -      CBA.getOSAndAlignedOffset(SHeader.sh_offset);
> +      CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
>     } else
>       llvm_unreachable("Unknown section type");
> 
> @@ -287,8 +289,9 @@ void ELFState<ELFT>::initSymtabSectionHe
>   addSymbols(Doc.Symbols.Global, Syms, ELF::STB_GLOBAL);
>   addSymbols(Doc.Symbols.Weak, Syms, ELF::STB_WEAK);
> 
> -  writeArrayData(CBA.getOSAndAlignedOffset(SHeader.sh_offset),
> -                 makeArrayRef(Syms));
> +  writeArrayData(
> +      CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign),
> +      makeArrayRef(Syms));
>   SHeader.sh_size = arrayDataSize(makeArrayRef(Syms));
> }
> 
> @@ -299,7 +302,8 @@ void ELFState<ELFT>::initStrtabSectionHe
>   zero(SHeader);
>   SHeader.sh_name = DotShStrtab.getOffset(Name);
>   SHeader.sh_type = ELF::SHT_STRTAB;
> -  CBA.getOSAndAlignedOffset(SHeader.sh_offset) << STB.data();
> +  CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign)
> +      << STB.data();
>   SHeader.sh_size = STB.data().size();
>   SHeader.sh_addralign = 1;
> }
> @@ -337,7 +341,8 @@ ELFState<ELFT>::writeSectionContent(Elf_
>                                     ContiguousBlobAccumulator &CBA) {
>   assert(Section.Size >= Section.Content.binary_size() &&
>          "Section size and section content are inconsistent");
> -  raw_ostream &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
> +  raw_ostream &OS =
> +      CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
>   Section.Content.writeAsBinary(OS);
>   for (auto i = Section.Content.binary_size(); i < Section.Size; ++i)
>     OS.write(0);
> @@ -364,7 +369,7 @@ ELFState<ELFT>::writeSectionContent(Elf_
>   SHeader.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
>   SHeader.sh_size = SHeader.sh_entsize * Section.Relocations.size();
> 
> -  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
> +  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
> 
>   for (const auto &Rel : Section.Relocations) {
>     unsigned SymIdx = 0;
> @@ -402,7 +407,7 @@ bool ELFState<ELFT>::writeSectionContent
>   SHeader.sh_entsize = sizeof(Elf_Word);
>   SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
> 
> -  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
> +  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
> 
>   for (auto member : Section.Members) {
>     Elf_Word SIdx;
> @@ -433,7 +438,7 @@ bool ELFState<ELFT>::writeSectionContent
>   SHeader.sh_entsize = sizeof(Flags);
>   SHeader.sh_size = SHeader.sh_entsize;
> 
> -  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset);
> +  auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
>   Flags.version = Section.Version;
>   Flags.isa_level = Section.ISALevel;
>   Flags.isa_rev = Section.ISARevision;
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150709/420dea94/attachment.html>


More information about the llvm-commits mailing list