[lld] r229314 - Update ARM and x86 ArchHandler to check switch completeness. NFC
Rui Ueyama
ruiu at google.com
Tue Feb 17 15:07:24 PST 2015
Nitpicky, but the mix of camel case and underscore (Arm_Kinds) looks odd.
Can we rename ArmKinds?
On Sun, Feb 15, 2015 at 7:23 AM, Jean-Daniel Dupas <devlists at shadowlab.org>
wrote:
> Author: jddupas
> Date: Sun Feb 15 09:23:48 2015
> New Revision: 229314
>
> URL: http://llvm.org/viewvc/llvm-project?rev=229314&view=rev
> Log:
> 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.
>
>
> Modified:
> lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
> lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
> lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp?rev=229314&r1=229313&r2=229314&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm.cpp Sun Feb 15
> 09:23:48 2015
> @@ -138,7 +138,7 @@ private:
> static const Registry::KindStrings _sKindStrings[];
> static const StubInfo _sStubInfoArmPIC;
>
> - enum : Reference::KindValue {
> + enum Arm_Kinds : Reference::KindValue {
> invalid, /// for error condition
>
> modeThumbCode, /// Content starting at this offset is thumb.
> @@ -207,6 +207,7 @@ ArchHandler_arm::ArchHandler_arm() { }
> ArchHandler_arm::~ArchHandler_arm() { }
>
> const Registry::KindStrings ArchHandler_arm::_sKindStrings[] = {
> + LLD_KIND_STRING_ENTRY(invalid),
> LLD_KIND_STRING_ENTRY(modeThumbCode),
> LLD_KIND_STRING_ENTRY(modeArmCode),
> LLD_KIND_STRING_ENTRY(modeData),
> @@ -912,7 +913,7 @@ void ArchHandler_arm::applyFixupFinal(co
> int32_t displacement;
> uint16_t value16;
> uint32_t value32;
> - switch (ref.kindValue()) {
> + switch (static_cast<Arm_Kinds>(ref.kindValue())) {
> case modeThumbCode:
> thumbMode = true;
> break;
> @@ -1068,13 +1069,16 @@ void ArchHandler_arm::applyFixupRelocata
> uint64_t inAtomAddress,
> bool &thumbMode,
> bool targetIsThumb) {
> + if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
> + return;
> + assert(ref.kindArch() == Reference::KindArch::ARM);
> bool useExternalReloc = useExternalRelocationTo(*ref.target());
> ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
> int32_t displacement;
> uint16_t value16;
> uint32_t value32;
> bool targetIsUndef = isa<UndefinedAtom>(ref.target());
> - switch (ref.kindValue()) {
> + switch (static_cast<Arm_Kinds>(ref.kindValue())) {
> case modeThumbCode:
> thumbMode = true;
> break;
> @@ -1168,7 +1172,7 @@ void ArchHandler_arm::applyFixupRelocata
> case lazyImmediateLocation:
> // do nothing
> break;
> - default:
> + case invalid:
> llvm_unreachable("invalid ARM Reference Kind");
> break;
> }
> @@ -1190,11 +1194,10 @@ void ArchHandler_arm::appendSectionReloc
> uint32_t targetAtomAddress;
> uint32_t fromAtomAddress;
> uint16_t other16;
> - switch (ref.kindValue()) {
> + switch (static_cast<Arm_Kinds>(ref.kindValue())) {
> case modeThumbCode:
> case modeArmCode:
> case modeData:
> - break;
> // Do nothing.
> break;
> case thumb_b22:
> @@ -1382,7 +1385,7 @@ void ArchHandler_arm::appendSectionReloc
> case lazyImmediateLocation:
> // do nothing
> break;
> - default:
> + case invalid:
> llvm_unreachable("invalid ARM Reference Kind");
> break;
> }
>
> Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=229314&r1=229313&r2=229314&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Sun Feb 15
> 09:23:48 2015
> @@ -133,7 +133,7 @@ private:
> static const Registry::KindStrings _sKindStrings[];
> static const StubInfo _sStubInfo;
>
> - enum : Reference::KindValue {
> + enum X86_Kinds : Reference::KindValue {
> invalid, /// for error condition
>
> modeCode, /// Content starting at this offset is code.
> @@ -441,7 +441,7 @@ void ArchHandler_x86::applyFixupFinal(co
> return;
> assert(ref.kindArch() == Reference::KindArch::x86);
> ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
> - switch (ref.kindValue()) {
> + switch (static_cast<X86_Kinds>(ref.kindValue())) {
> case branch32:
> *loc32 = (targetAddress - (fixupAddress + 4)) + ref.addend();
> break;
> @@ -469,7 +469,7 @@ void ArchHandler_x86::applyFixupFinal(co
> case lazyImmediateLocation:
> *loc32 = ref.addend();
> break;
> - default:
> + case invalid:
> llvm_unreachable("invalid x86 Reference Kind");
> break;
> }
> @@ -480,10 +480,13 @@ void ArchHandler_x86::applyFixupRelocata
> uint64_t fixupAddress,
> uint64_t targetAddress,
> uint64_t inAtomAddress) {
> + if (ref.kindNamespace() != Reference::KindNamespace::mach_o)
> + return;
> + assert(ref.kindArch() == Reference::KindArch::x86);
> bool useExternalReloc = useExternalRelocationTo(*ref.target());
> ulittle16_t *loc16 = reinterpret_cast<ulittle16_t *>(loc);
> ulittle32_t *loc32 = reinterpret_cast<ulittle32_t *>(loc);
> - switch (ref.kindValue()) {
> + switch (static_cast<X86_Kinds>(ref.kindValue())) {
> case branch32:
> if (useExternalReloc)
> *loc32 = ref.addend() - (fixupAddress + 4);
> @@ -515,7 +518,7 @@ void ArchHandler_x86::applyFixupRelocata
> case lazyImmediateLocation:
> // do nothing
> break;
> - default:
> + case invalid:
> llvm_unreachable("invalid x86 Reference Kind");
> break;
> }
> @@ -556,7 +559,7 @@ void ArchHandler_x86::appendSectionReloc
> assert(ref.kindArch() == Reference::KindArch::x86);
> uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom();
> bool useExternalReloc = useExternalRelocationTo(*ref.target());
> - switch (ref.kindValue()) {
> + switch (static_cast<X86_Kinds>(ref.kindValue())) {
> case modeCode:
> case modeData:
> break;
> @@ -624,10 +627,9 @@ void ArchHandler_x86::appendSectionReloc
> case lazyImmediateLocation:
> llvm_unreachable("lazy reference kind implies Stubs pass was run");
> break;
> - default:
> + case invalid:
> llvm_unreachable("unknown x86 Reference Kind");
> break;
> -
> }
> }
>
>
> Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp?rev=229314&r1=229313&r2=229314&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp Sun Feb 15
> 09:23:48 2015
> @@ -475,11 +475,11 @@ void ArchHandler_x86_64::applyFixupFinal
> const Reference &ref, uint8_t *loc, uint64_t fixupAddress,
> uint64_t targetAddress, uint64_t inAtomAddress, uint64_t
> imageBaseAddress,
> 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)
> return;
> 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())) {
> case branch32:
> case ripRel32:
> @@ -548,6 +548,9 @@ void ArchHandler_x86_64::applyFixupReloc
> uint64_t fixupAddress,
> uint64_t targetAddress,
> 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);
> ulittle64_t *loc64 = reinterpret_cast<ulittle64_t *>(loc);
> switch (static_cast<X86_64_Kinds>(ref.kindValue())) {
>
>
> _______________________________________________
> 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/20150217/83b0014e/attachment.html>
More information about the llvm-commits
mailing list