forked from OSchip/llvm-project
				
			Update ARM and x86 ArchHandler to check switch completeness. NFC
Define an explicit type for arch specific reference kinds to make sure all cases are covered in switch statements. llvm-svn: 229314
This commit is contained in:
		
							parent
							
								
									5a6375c3ba
								
							
						
					
					
						commit
						9c222630e4
					
				| 
						 | 
					@ -138,7 +138,7 @@ private:
 | 
				
			||||||
  static const Registry::KindStrings _sKindStrings[];
 | 
					  static const Registry::KindStrings _sKindStrings[];
 | 
				
			||||||
  static const StubInfo              _sStubInfoArmPIC;
 | 
					  static const StubInfo              _sStubInfoArmPIC;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  enum : Reference::KindValue {
 | 
					  enum Arm_Kinds : Reference::KindValue {
 | 
				
			||||||
    invalid,               /// for error condition
 | 
					    invalid,               /// for error condition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    modeThumbCode,         /// Content starting at this offset is thumb.
 | 
					    modeThumbCode,         /// Content starting at this offset is thumb.
 | 
				
			||||||
| 
						 | 
					@ -207,6 +207,7 @@ ArchHandler_arm::ArchHandler_arm() { }
 | 
				
			||||||
ArchHandler_arm::~ArchHandler_arm() { }
 | 
					ArchHandler_arm::~ArchHandler_arm() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Registry::KindStrings ArchHandler_arm::_sKindStrings[] = {
 | 
					const Registry::KindStrings ArchHandler_arm::_sKindStrings[] = {
 | 
				
			||||||
 | 
					  LLD_KIND_STRING_ENTRY(invalid),
 | 
				
			||||||
  LLD_KIND_STRING_ENTRY(modeThumbCode),
 | 
					  LLD_KIND_STRING_ENTRY(modeThumbCode),
 | 
				
			||||||
  LLD_KIND_STRING_ENTRY(modeArmCode),
 | 
					  LLD_KIND_STRING_ENTRY(modeArmCode),
 | 
				
			||||||
  LLD_KIND_STRING_ENTRY(modeData),
 | 
					  LLD_KIND_STRING_ENTRY(modeData),
 | 
				
			||||||
| 
						 | 
					@ -912,7 +913,7 @@ void ArchHandler_arm::applyFixupFinal(const Reference &ref, uint8_t *loc,
 | 
				
			||||||
  int32_t displacement;
 | 
					  int32_t displacement;
 | 
				
			||||||
  uint16_t value16;
 | 
					  uint16_t value16;
 | 
				
			||||||
  uint32_t value32;
 | 
					  uint32_t value32;
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<Arm_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case modeThumbCode:
 | 
					  case modeThumbCode:
 | 
				
			||||||
    thumbMode = true;
 | 
					    thumbMode = true;
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
| 
						 | 
					@ -1068,13 +1069,16 @@ void ArchHandler_arm::applyFixupRelocatable(const Reference &ref, uint8_t *loc,
 | 
				
			||||||
                                            uint64_t inAtomAddress,
 | 
					                                            uint64_t inAtomAddress,
 | 
				
			||||||
                                            bool &thumbMode,
 | 
					                                            bool &thumbMode,
 | 
				
			||||||
                                            bool targetIsThumb) {
 | 
					                                            bool targetIsThumb) {
 | 
				
			||||||
 | 
					  if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  assert(ref.kindArch() == Reference::KindArch::ARM);
 | 
				
			||||||
  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
					  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
				
			||||||
  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
					  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
				
			||||||
  int32_t displacement;
 | 
					  int32_t displacement;
 | 
				
			||||||
  uint16_t value16;
 | 
					  uint16_t value16;
 | 
				
			||||||
  uint32_t value32;
 | 
					  uint32_t value32;
 | 
				
			||||||
  bool targetIsUndef = isa<UndefinedAtom>(ref.target());
 | 
					  bool targetIsUndef = isa<UndefinedAtom>(ref.target());
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<Arm_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case modeThumbCode:
 | 
					  case modeThumbCode:
 | 
				
			||||||
    thumbMode = true;
 | 
					    thumbMode = true;
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
| 
						 | 
					@ -1168,7 +1172,7 @@ void ArchHandler_arm::applyFixupRelocatable(const Reference &ref, uint8_t *loc,
 | 
				
			||||||
  case lazyImmediateLocation:
 | 
					  case lazyImmediateLocation:
 | 
				
			||||||
    // do nothing
 | 
					    // do nothing
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  case invalid:
 | 
				
			||||||
    llvm_unreachable("invalid ARM Reference Kind");
 | 
					    llvm_unreachable("invalid ARM Reference Kind");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -1190,11 +1194,10 @@ void ArchHandler_arm::appendSectionRelocations(
 | 
				
			||||||
  uint32_t targetAtomAddress;
 | 
					  uint32_t targetAtomAddress;
 | 
				
			||||||
  uint32_t fromAtomAddress;
 | 
					  uint32_t fromAtomAddress;
 | 
				
			||||||
  uint16_t other16;
 | 
					  uint16_t other16;
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<Arm_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case modeThumbCode:
 | 
					  case modeThumbCode:
 | 
				
			||||||
  case modeArmCode:
 | 
					  case modeArmCode:
 | 
				
			||||||
  case modeData:
 | 
					  case modeData:
 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
    // Do nothing.
 | 
					    // Do nothing.
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case thumb_b22:
 | 
					  case thumb_b22:
 | 
				
			||||||
| 
						 | 
					@ -1382,7 +1385,7 @@ void ArchHandler_arm::appendSectionRelocations(
 | 
				
			||||||
  case lazyImmediateLocation:
 | 
					  case lazyImmediateLocation:
 | 
				
			||||||
    // do nothing
 | 
					    // do nothing
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  case invalid:
 | 
				
			||||||
    llvm_unreachable("invalid ARM Reference Kind");
 | 
					    llvm_unreachable("invalid ARM Reference Kind");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,7 +133,7 @@ private:
 | 
				
			||||||
  static const Registry::KindStrings _sKindStrings[];
 | 
					  static const Registry::KindStrings _sKindStrings[];
 | 
				
			||||||
  static const StubInfo              _sStubInfo;
 | 
					  static const StubInfo              _sStubInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  enum : Reference::KindValue {
 | 
					  enum X86_Kinds : Reference::KindValue {
 | 
				
			||||||
    invalid,               /// for error condition
 | 
					    invalid,               /// for error condition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    modeCode,              /// Content starting at this offset is code.
 | 
					    modeCode,              /// Content starting at this offset is code.
 | 
				
			||||||
| 
						 | 
					@ -441,7 +441,7 @@ void ArchHandler_x86::applyFixupFinal(const Reference &ref, uint8_t *loc,
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  assert(ref.kindArch() == Reference::KindArch::x86);
 | 
					  assert(ref.kindArch() == Reference::KindArch::x86);
 | 
				
			||||||
  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
					  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<X86_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case branch32:
 | 
					  case branch32:
 | 
				
			||||||
    *loc32 = (targetAddress - (fixupAddress + 4)) + ref.addend();
 | 
					    *loc32 = (targetAddress - (fixupAddress + 4)) + ref.addend();
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
| 
						 | 
					@ -469,7 +469,7 @@ void ArchHandler_x86::applyFixupFinal(const Reference &ref, uint8_t *loc,
 | 
				
			||||||
  case lazyImmediateLocation:
 | 
					  case lazyImmediateLocation:
 | 
				
			||||||
    *loc32 = ref.addend();
 | 
					    *loc32 = ref.addend();
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  case invalid:
 | 
				
			||||||
    llvm_unreachable("invalid x86 Reference Kind");
 | 
					    llvm_unreachable("invalid x86 Reference Kind");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -480,10 +480,13 @@ void ArchHandler_x86::applyFixupRelocatable(const Reference &ref,
 | 
				
			||||||
                                               uint64_t fixupAddress,
 | 
					                                               uint64_t fixupAddress,
 | 
				
			||||||
                                               uint64_t targetAddress,
 | 
					                                               uint64_t targetAddress,
 | 
				
			||||||
                                               uint64_t inAtomAddress) {
 | 
					                                               uint64_t inAtomAddress) {
 | 
				
			||||||
 | 
					  if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  assert(ref.kindArch() == Reference::KindArch::x86);
 | 
				
			||||||
  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
					  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
				
			||||||
  ulittle16_t *loc16 = reinterpret_cast<ulittle16_t *>(loc);
 | 
					  ulittle16_t *loc16 = reinterpret_cast<ulittle16_t *>(loc);
 | 
				
			||||||
  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
					  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<X86_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case branch32:
 | 
					  case branch32:
 | 
				
			||||||
    if (useExternalReloc)
 | 
					    if (useExternalReloc)
 | 
				
			||||||
      *loc32 = ref.addend() - (fixupAddress + 4);
 | 
					      *loc32 = ref.addend() - (fixupAddress + 4);
 | 
				
			||||||
| 
						 | 
					@ -515,7 +518,7 @@ void ArchHandler_x86::applyFixupRelocatable(const Reference &ref,
 | 
				
			||||||
  case lazyImmediateLocation:
 | 
					  case lazyImmediateLocation:
 | 
				
			||||||
    // do nothing
 | 
					    // do nothing
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  case invalid:
 | 
				
			||||||
    llvm_unreachable("invalid x86 Reference Kind");
 | 
					    llvm_unreachable("invalid x86 Reference Kind");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -556,7 +559,7 @@ void ArchHandler_x86::appendSectionRelocations(
 | 
				
			||||||
  assert(ref.kindArch() == Reference::KindArch::x86);
 | 
					  assert(ref.kindArch() == Reference::KindArch::x86);
 | 
				
			||||||
  uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom();
 | 
					  uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom();
 | 
				
			||||||
  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
					  bool useExternalReloc = useExternalRelocationTo(*ref.target());
 | 
				
			||||||
  switch (ref.kindValue()) {
 | 
					  switch (static_cast<X86_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case modeCode:
 | 
					  case modeCode:
 | 
				
			||||||
  case modeData:
 | 
					  case modeData:
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
| 
						 | 
					@ -624,10 +627,9 @@ void ArchHandler_x86::appendSectionRelocations(
 | 
				
			||||||
  case lazyImmediateLocation:
 | 
					  case lazyImmediateLocation:
 | 
				
			||||||
    llvm_unreachable("lazy reference kind implies Stubs pass was run");
 | 
					    llvm_unreachable("lazy reference kind implies Stubs pass was run");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  case invalid:
 | 
				
			||||||
    llvm_unreachable("unknown x86 Reference Kind");
 | 
					    llvm_unreachable("unknown x86 Reference Kind");
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -475,11 +475,11 @@ void ArchHandler_x86_64::applyFixupFinal(
 | 
				
			||||||
    const Reference &ref, uint8_t *loc, uint64_t fixupAddress,
 | 
					    const Reference &ref, uint8_t *loc, uint64_t fixupAddress,
 | 
				
			||||||
    uint64_t targetAddress, uint64_t inAtomAddress, uint64_t imageBaseAddress,
 | 
					    uint64_t targetAddress, uint64_t inAtomAddress, uint64_t imageBaseAddress,
 | 
				
			||||||
    FindAddressForAtom findSectionAddress) {
 | 
					    FindAddressForAtom findSectionAddress) {
 | 
				
			||||||
  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
					 | 
				
			||||||
  ulittle64_t *loc64 = reinterpret_cast<ulittle64_t *>(loc);
 | 
					 | 
				
			||||||
  if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
 | 
					  if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  assert(ref.kindArch() == Reference::KindArch::x86_64);
 | 
					  assert(ref.kindArch() == Reference::KindArch::x86_64);
 | 
				
			||||||
 | 
					  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
				
			||||||
 | 
					  ulittle64_t *loc64 = reinterpret_cast<ulittle64_t *>(loc);
 | 
				
			||||||
  switch (static_cast<X86_64_Kinds>(ref.kindValue())) {
 | 
					  switch (static_cast<X86_64_Kinds>(ref.kindValue())) {
 | 
				
			||||||
  case branch32:
 | 
					  case branch32:
 | 
				
			||||||
  case ripRel32:
 | 
					  case ripRel32:
 | 
				
			||||||
| 
						 | 
					@ -548,6 +548,9 @@ void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,
 | 
				
			||||||
                                               uint64_t fixupAddress,
 | 
					                                               uint64_t fixupAddress,
 | 
				
			||||||
                                               uint64_t targetAddress,
 | 
					                                               uint64_t targetAddress,
 | 
				
			||||||
                                               uint64_t inAtomAddress)  {
 | 
					                                               uint64_t inAtomAddress)  {
 | 
				
			||||||
 | 
					  if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  assert(ref.kindArch() == Reference::KindArch::x86_64);
 | 
				
			||||||
  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
					  ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
 | 
				
			||||||
  ulittle64_t *loc64 = reinterpret_cast<ulittle64_t *>(loc);
 | 
					  ulittle64_t *loc64 = reinterpret_cast<ulittle64_t *>(loc);
 | 
				
			||||||
  switch (static_cast<X86_64_Kinds>(ref.kindValue())) {
 | 
					  switch (static_cast<X86_64_Kinds>(ref.kindValue())) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue