[PATCH] D58102: Support X86 Control-flow Enforcement Technology (CET) in LLD

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 03:32:28 PDT 2019


peter.smith added a comment.

In D58102#1436011 <https://reviews.llvm.org/D58102#1436011>, @xiangzhangllvm wrote:

> I rewrited the collecting feature functions.
>  It is very simple now!
>
>   +struct GnuPropertyHeadType {
>   +  uint32_t Namesz;
>   +  uint32_t Descsz;
>   +  uint32_t NType;
>   +  uint32_t Name;
>   +};                                              // Did here need packed attribute ? I have a little concern
>   +
>   +struct GnuPropertyDescType {
>   +  uint32_t DescTy;
>   +  uint32_t Descsz;
>   +  uint32_t Feature;
>   +  uint32_t Pad;
>   +};                                              // Did here need packed attribute ? I have a little concern
>   +
>   +struct GnuPropertyType {
>   +  GnuPropertyHeadType Head;
>   +  GnuPropertyDescType Desc[];
>   +};                                            // Did here need packed attribute ? I have a little concern
>   +
>   +static bool findGNUPropertyX86Feature1AND(InputSectionBase *S,
>   +                                          unsigned &Features) {
>   +  auto Data = S->getDataAs<uint32_t>();
>   +  GnuPropertyType *GnuProperty = cast<GnuPropertyType>(Data.data());
>   +  size_t DescNum = GnuProperty->Head.Descsz / sizeof (GnuPropertyDescType);
>   +  if (GnuProperty->Head.NType != NT_GNU_PROPERTY_TYPE_0)
>   +    return false;
>   +  for (size_t i = 0; i < DescNum; i ++) {
>   +    if (GnuProperty->Desc[i].DescTy == GNU_PROPERTY_X86_FEATURE_1_AND) {
>   +      Features = GnuProperty->Desc[i].Feature;
>   +      return true;
>   +    }
>   +  }
>   +  return false;
>   +}
>


I'm having problems getting this to compile on at least GCC 5.4.0 on Linux:

  lld/ELF/SyntheticSections.cpp:3104:28: warning: ISO C++ forbids zero-size array ‘Desc’ [-Wpedantic]
     GnuPropertyDescType Desc[]
  
  lld/ELF/SyntheticSections.cpp:3110:55: error: invalid conversion from ‘llvm::cast_retty<GnuPropertyType, const unsigned int*>::ret_type {aka const GnuPropertyType*}’ to ‘GnuPropertyType*’ [-fpermissive]
     GnuPropertyType *GnuProperty = cast<GnuPropertyType>(Data.data());

The cast<> is an LLVM cast http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates and isn't something you can do on an arbitrary struct.

Assuming (x86) that your input data is always little endian then you'll need to use something like ulittle32_t instead of uint32_t or your tests will fail when run on a big-endian machine like PPC or some Mips machines.


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D58102





More information about the llvm-commits mailing list