llvm.org GIT mirror llvm / 15479d5
Fix DWARF DebugInfo unit test errors when cross-compiling Summary: When building with a Default Target set we can experience issues in the DWARF DebugInfo unit tests because: They assume we can generate object files for the host platform. Some tests assume the endianess of the target we are generating DWARF for and the host match. This patch correct these issues by ensuring the tests which generate objects in memory are run with respect to LVM_DEFAULT_TARGET_TRIPLE and it's endianess. We also make sure we don't use the hosts address size for line test and split the triple util function in DwarfUtils into a version that takes an address size and one that doesn't. See also for discussion: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131212.html Patch by: daltenty Differential Revision: https://reviews.llvm.org/D62084 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362454 91177308-0d34-0410-b5e6-96231b3b80d8 Jason Liu a month ago
4 changed file(s) with 32 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
4040
4141 template
4242 void TestAllForms() {
43 Triple Triple = getHostTripleForAddrSize(sizeof(AddrType));
43 Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType));
4444 if (!isConfigurationSupported(Triple))
4545 return;
4646
454454 }
455455
456456 template void TestChildren() {
457 Triple Triple = getHostTripleForAddrSize(sizeof(AddrType));
457 Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType));
458458 if (!isConfigurationSupported(Triple))
459459 return;
460460
584584 }
585585
586586 template void TestReferences() {
587 Triple Triple = getHostTripleForAddrSize(sizeof(AddrType));
587 Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType));
588588 if (!isConfigurationSupported(Triple))
589589 return;
590590
834834 }
835835
836836 template void TestAddresses() {
837 Triple Triple = getHostTripleForAddrSize(sizeof(AddrType));
837 Triple Triple = getDefaultTargetTripleForAddrSize(sizeof(AddrType));
838838 if (!isConfigurationSupported(Triple))
839839 return;
840840
10061006 }
10071007
10081008 TEST(DWARFDebugInfo, TestStringOffsets) {
1009 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1009 Triple Triple = getNormalizedDefaultTargetTriple();
10101010 if (!isConfigurationSupported(Triple))
10111011 return;
10121012
10701070 }
10711071
10721072 TEST(DWARFDebugInfo, TestEmptyStringOffsets) {
1073 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1073 Triple Triple = getNormalizedDefaultTargetTriple();
10741074 if (!isConfigurationSupported(Triple))
10751075 return;
10761076
10991099 }
11001100
11011101 TEST(DWARFDebugInfo, TestRelations) {
1102 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1102 Triple Triple = getNormalizedDefaultTargetTriple();
11031103 if (!isConfigurationSupported(Triple))
11041104 return;
11051105
12861286 }
12871287
12881288 TEST(DWARFDebugInfo, TestChildIterators) {
1289 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1289 Triple Triple = getNormalizedDefaultTargetTriple();
12901290 if (!isConfigurationSupported(Triple))
12911291 return;
12921292
14001400 }
14011401
14021402 TEST(DWARFDebugInfo, TestAttributeIterators) {
1403 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1403 Triple Triple = getNormalizedDefaultTargetTriple();
14041404 if (!isConfigurationSupported(Triple))
14051405 return;
14061406
14621462 }
14631463
14641464 TEST(DWARFDebugInfo, TestFindRecurse) {
1465 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1465 Triple Triple = getNormalizedDefaultTargetTriple();
14661466 if (!isConfigurationSupported(Triple))
14671467 return;
14681468
16761676 }
16771677
16781678 TEST(DWARFDebugInfo, TestFindAttrs) {
1679 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1679 Triple Triple = getNormalizedDefaultTargetTriple();
16801680 if (!isConfigurationSupported(Triple))
16811681 return;
16821682
17391739 }
17401740
17411741 TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) {
1742 Triple Triple = getHostTripleForAddrSize(sizeof(void *));
1742 Triple Triple = getNormalizedDefaultTargetTriple();
17431743 if (!isConfigurationSupported(Triple))
17441744 return;
17451745
3636 }
3737
3838 bool setupGenerator(uint16_t Version = 4) {
39 Triple T = getHostTripleForAddrSize(8);
39 Triple T = getDefaultTargetTripleForAddrSize(8);
4040 if (!isConfigurationSupported(T))
4141 return false;
4242 auto ExpectedGenerator = Generator::create(T, Version);
4949 Context = createContext();
5050 assert(Context != nullptr && "test state is not valid");
5151 const DWARFObject &Obj = Context->getDWARFObj();
52 LineData = DWARFDataExtractor(Obj, Obj.getLineSection(),
53 sys::IsLittleEndianHost, 8);
52 LineData = DWARFDataExtractor(
53 Obj, Obj.getLineSection(),
54 getDefaultTargetTripleForAddrSize(8).isLittleEndian(), 8);
5455 }
5556
5657 std::unique_ptr createContext() {
88 #include "DwarfUtils.h"
99 #include "llvm/ADT/Triple.h"
1010 #include "llvm/Config/llvm-config.h"
11 #include "llvm/Support/Host.h"
1112 #include "llvm/Support/TargetRegistry.h"
1213 #include "llvm/Support/TargetSelect.h"
1314
2425 }
2526 }
2627
27 Triple llvm::dwarf::utils::getHostTripleForAddrSize(uint8_t AddrSize) {
28 Triple T(Triple::normalize(LLVM_HOST_TRIPLE));
28 Triple llvm::dwarf::utils::getNormalizedDefaultTargetTriple() {
29 Triple T(Triple::normalize(sys::getDefaultTargetTriple()));
2930
31 return T;
32 }
33
34 Triple llvm::dwarf::utils::getDefaultTargetTripleForAddrSize(uint8_t AddrSize) {
35 Triple T = getNormalizedDefaultTargetTriple();
36
37 assert((AddrSize == 4 || AddrSize == 8) &&
38 "Only 32-bit/64-bit address size variants are supported");
39
40 // If a 32-bit/64-bit address size was specified, try to convert the triple
41 // if it is for the wrong variant.
3042 if (AddrSize == 8 && T.isArch32Bit())
3143 return T.get64BitArchVariant();
3244 if (AddrSize == 4 && T.isArch64Bit())
1717 namespace dwarf {
1818 namespace utils {
1919
20 Triple getHostTripleForAddrSize(uint8_t AddrSize);
20 Triple getDefaultTargetTripleForAddrSize(uint8_t AddrSize);
21 Triple getNormalizedDefaultTargetTriple();
2122 bool isConfigurationSupported(Triple &T);
2223
2324 } // end namespace utils