[llvm-commits] [llvm] r81424 - /llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp

Duncan Sands baldrick at free.fr
Wed Sep 9 22:04:58 PDT 2009


Hi Bill,

> Don't hardcode the TType format size. In fact, rework the code so that it's more
> like what GCC outputs. The mysterious code to insert padding wasn't in GCC at
> all.

woah, be careful here!  The type infos need to be aligned.  GCC does
this by inserting padding just before the type infos.  However this
changes the size of the exception table, so you need to take this into
account when you output the exception table size.  However, the size is
output using a variable length encoding.  So by increasing the size by
inserting padding, you may increase the number of bytes used for writing
the size.  If it increases, say by one byte, then you now need to output
one less byte of padding to get the typeinfos aligned.  However this
decreases the size of the exception table.  This changes the value you
have to output for the exception table size.  Due to the variable length
encoding, the number of bytes used for writing the length may decrease.
If so, you then have to increase the amount of padding.  And so on.  If
you look carefully at the GCC code you will see that it indeed does this
in a loop, going on and on until the values stabilize (if they ever do -
I couldn't convince myself that they always would).  Because this was so
horrible, I chose another solution: don't output padding inside the
table like GCC does, instead output it before the table.

So please don't follow GCC here, and please don't output alignment
directives inside the table - it's a horrible can of worms.

Ciao,

Duncan.


I modified the TType base offset code to calculate the offset like GCC
> does, though.
> 
> Modified:
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=81424&r1=81423&r2=81424&view=diff
> 
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp Wed Sep  9 21:07:37 2009
> @@ -617,53 +617,11 @@
>    }
>  
>    // Type infos.
> -  // FIXME: Don't hardcode. Should be TType's format encoding size.
> -  unsigned TypeInfoSize = SizeOfEncodedValue(dwarf::DW_EH_PE_absptr);
> -  unsigned SizeTypes = TypeInfos.size() * TypeInfoSize;
> -
> -  unsigned TypeOffset = sizeof(int8_t) +   // Call site format
> -    MCAsmInfo::getULEB128Size(SizeSites) + // Call-site table length
> -    SizeSites + SizeActions + SizeTypes;
> -
> -  unsigned TotalSize = sizeof(int8_t) + // LPStart format
> -                       sizeof(int8_t) + // TType format
> -       (HaveTTData ?
> -          MCAsmInfo::getULEB128Size(TypeOffset) : 0) + // TType base offset
> -                       TypeOffset;
> -
> -  unsigned SizeAlign = (4 - TotalSize) & 3;
> -
> -  // Begin the exception table.
>    const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
> -  Asm->OutStreamer.SwitchSection(LSDASection);
> -  Asm->EmitAlignment(2, 0, 0, false);
> -  O << "GCC_except_table" << SubprogramCount << ":\n";
> +  unsigned TTypeFormat;
>  
> -  for (unsigned i = 0; i != SizeAlign; ++i) {
> -    Asm->EmitInt8(0);
> -    Asm->EOL("Padding");
> -  }
> -
> -  EmitLabel("exception", SubprogramCount);
> -  if (IsSJLJ) {
> -    SmallString<16> LSDAName;
> -    raw_svector_ostream(LSDAName) << MAI->getPrivateGlobalPrefix() <<
> -      "_LSDA_" << Asm->getFunctionNumber();
> -    O << LSDAName.str() << ":\n";
> -  }
> -
> -  // Emit the header.
> -  Asm->EmitInt8(dwarf::DW_EH_PE_omit);
> -  Asm->EOL("@LPStart format", dwarf::DW_EH_PE_omit);
> -
> -  // For SjLj exceptions, if there is no TypeInfo, then we just explicitly
> -  // say that we're omitting that bit.
> -  // FIXME: does this apply to Dwarf also? The above #if 0 implies yes?
>    if (!HaveTTData) {
> -    // If there are no typeinfos or filters, there is nothing to emit, optimize
> -    // by specifying the "omit" encoding.
> -    Asm->EmitInt8(dwarf::DW_EH_PE_omit);
> -    Asm->EOL("@TType format", dwarf::DW_EH_PE_omit);
> +    TTypeFormat = dwarf::DW_EH_PE_omit;
>    } else {
>      // Okay, we have actual filters or typeinfos to emit.  As such, we need to
>      // pick a type encoding for them.  We're about to emit a list of pointers to
> @@ -689,19 +647,61 @@
>      // somewhere.  This predicate should be moved to a shared location that is
>      // in target-independent code.
>      //
> -    unsigned TTypeFormat;
> -
>      if (LSDASection->getKind().isWriteable() ||
>          Asm->TM.getRelocationModel() == Reloc::Static)
>        TTypeFormat = dwarf::DW_EH_PE_absptr;
>      else
>        TTypeFormat = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
>          dwarf::DW_EH_PE_sdata4;
> +  }
>  
> -    Asm->EmitInt8(TTypeFormat);
> -    Asm->EOL("@TType format", TTypeFormat);
> +  // Begin the exception table.
> +  Asm->OutStreamer.SwitchSection(LSDASection);
> +  Asm->EmitAlignment(2, 0, 0, false);
> +
> +  O << "GCC_except_table" << SubprogramCount << ":\n";
> +  EmitLabel("exception", SubprogramCount);
> +
> +  if (IsSJLJ) {
> +    SmallString<16> LSDAName;
> +    raw_svector_ostream(LSDAName) << MAI->getPrivateGlobalPrefix() <<
> +      "_LSDA_" << Asm->getFunctionNumber();
> +    O << LSDAName.str() << ":\n";
> +  }
> +
> +  // Emit the header.
> +  Asm->EmitInt8(dwarf::DW_EH_PE_omit);
> +  Asm->EOL("@LPStart format", dwarf::DW_EH_PE_omit);
> +
> +  // For SjLj exceptions, if there is no TypeInfo, then we just explicitly
> +  // say that we're omitting that bit.
> +  Asm->EmitInt8(TTypeFormat);
> +  Asm->EOL("@TType format", TTypeFormat);
> +
> +  if (HaveTTData) {
> +    unsigned TypeFormatSize = SizeOfEncodedValue(TTypeFormat);
> +    unsigned SizeTypes = TypeInfos.size() * TypeFormatSize;
> +    unsigned BeforeOffset = 2;
> +    unsigned TypeOffset = sizeof(int8_t) +   // Call site format
> +      MCAsmInfo::getULEB128Size(SizeSites) + // Call-site table length
> +      SizeSites + SizeActions + SizeTypes;
> +    unsigned Offset = TypeOffset;
> +    unsigned LastOffset = 0;
> +
> +    while (Offset != LastOffset) {
> +      LastOffset = Offset;
> +      unsigned Size = MCAsmInfo::getULEB128Size(Offset);
> +      unsigned Pad = BeforeOffset + Size + TypeOffset;
> +
> +      if (Pad % TypeFormatSize)
> +        Pad = TypeFormatSize - (Pad % TypeFormatSize);
> +      else
> +        Pad = 0;
> +
> +      Offset = TypeOffset + Pad;
> +    }
>  
> -    Asm->EmitULEB128Bytes(TypeOffset);
> +    Asm->EmitULEB128Bytes(Offset);
>      Asm->EOL("@TType base offset");
>    }
>  
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list