From 9ee68e3f729e95a12e9f266a09e8ffdbaeda83f2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 12 Dec 2012 06:18:15 +0000 Subject: Remove some dead code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169963 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index da7615714e..a38fac78aa 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -447,9 +447,7 @@ error_code MachOObjectFile::getSectionNext(DataRefImpl DRI, void MachOObjectFile::getSection(DataRefImpl DRI, InMemoryStruct &Res) const { - InMemoryStruct SLC; LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - MachOObj->ReadSegmentLoadCommand(LCI, SLC); MachOObj->ReadSection(LCI, DRI.d.b, Res); } @@ -463,9 +461,7 @@ std::size_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const { void MachOObjectFile::getSection64(DataRefImpl DRI, InMemoryStruct &Res) const { - InMemoryStruct SLC; LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - MachOObj->ReadSegment64LoadCommand(LCI, SLC); MachOObj->ReadSection64(LCI, DRI.d.b, Res); } @@ -482,9 +478,7 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI, // FIXME: thread safety. static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { - InMemoryStruct SLC; LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - MachOObj->ReadSegment64LoadCommand(LCI, SLC); InMemoryStruct Sect; MachOObj->ReadSection64(LCI, DRI.d.b, Sect); @@ -492,9 +486,7 @@ error_code MachOObjectFile::getSectionName(DataRefImpl DRI, strcat(result, ","); strcat(result, Sect->Name); } else { - InMemoryStruct SLC; LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - MachOObj->ReadSegmentLoadCommand(LCI, SLC); InMemoryStruct Sect; MachOObj->ReadSection(LCI, DRI.d.b, Sect); -- cgit v1.2.3-70-g09d2 From e3ec87a6f7b718596697727e699a62aed0d40b25 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Dec 2012 04:07:18 +0000 Subject: Add a funciton to get the segment name of a section. On MachO, sections also have segment names. When a tool looking at a .o file prints a segment name, this is what they mean. In reality, a .o has only one, anonymous, segment. This patch adds a MachO only function to fetch that segment name. I named it getSectionFinalSegmentName since the main use for the name seems to be informing the linker with segment this section should go to. The patch also changes MachOObjectFile::getSectionName to return just the section name instead of computing SegmentName,SectionName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170095 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 5 +++++ lib/Object/MachOObjectFile.cpp | 35 +++++++++++++++++++++++++---------- tools/llvm-objdump/MachODump.cpp | 8 +++++++- tools/llvm-objdump/llvm-objdump.cpp | 14 +++++++++++--- 4 files changed, 48 insertions(+), 14 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index da972a2433..ed7aabd2c8 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -44,6 +44,11 @@ public: virtual unsigned getArch() const; virtual StringRef getLoadName() const; + // In a MachO file, sections have a segment name. This is used in the .o + // files. They have a single segment, but this field specifies which segment + // a section should be put in in the final object. + error_code getSectionFinalSegmentName(DataRefImpl Sec, StringRef &Res) const; + MachOObject *getObject() { return MachOObj.get(); } static inline bool classof(const Binary *v) { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a38fac78aa..392563ad19 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -473,28 +473,43 @@ static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) { return false; } +static StringRef parseSegmentOrSectionName(const char *P) { + if (P[15] == 0) + // Null terminated. + return P; + // Not null terminated, so this is a 16 char string. + return StringRef(P, 16); +} + error_code MachOObjectFile::getSectionName(DataRefImpl DRI, StringRef &Result) const { - // FIXME: thread safety. - static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection64(LCI, DRI.d.b, Sect); - - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); + Result = parseSegmentOrSectionName(Sect->Name); } else { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection(LCI, DRI.d.b, Sect); + Result = parseSegmentOrSectionName(Sect->Name); + } + return object_error::success; +} - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); +error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec, + StringRef &Res) const { + if (is64BitLoadCommand(MachOObj.get(), Sec)) { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + InMemoryStruct Sect; + MachOObj->ReadSection64(LCI, Sec.d.b, Sect); + Res = parseSegmentOrSectionName(Sect->SegmentName); + } else { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + InMemoryStruct Sect; + MachOObj->ReadSection(LCI, Sec.d.b, Sect); + Res = parseSegmentOrSectionName(Sect->SegmentName); } - Result = StringRef(result); return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3a350382ae..c324ff13a6 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -334,9 +334,15 @@ void llvm::DisassembleInputMachO(StringRef Filename) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { StringRef SectName; if (Sections[SectIdx].getName(SectName) || - SectName.compare("__TEXT,__text")) + SectName != "__text") continue; // Skip non-text sections + StringRef SegmentName; + DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); + if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) || + SegmentName != "__TEXT") + continue; + // Insert the functions from the function starts segment into our map. uint64_t VMAddr; Sections[SectIdx].getAddress(VMAddr); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 2838a2a2b3..9edcae8d6b 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -28,6 +28,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -72,9 +73,9 @@ static cl::opt SymbolTable("t", cl::desc("Display the symbol table")); static cl::opt -MachO("macho", cl::desc("Use MachO specific object file parser")); +MachOOpt("macho", cl::desc("Use MachO specific object file parser")); static cl::alias -MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachO)); +MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt)); cl::opt llvm::TripleName("triple", cl::desc("Target triple to disassemble for, " @@ -567,6 +568,13 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Section == o->end_sections()) outs() << "*UND*"; else { + if (const MachOObjectFile *MachO = dyn_cast(o)) { + StringRef SegmentName; + DataRefImpl DR = Section->getRawDataRefImpl(); + if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) + SegmentName = ""; + outs() << SegmentName << ","; + } StringRef SectionName; if (error(Section->getName(SectionName))) SectionName = ""; @@ -640,7 +648,7 @@ static void DumpInput(StringRef file) { return; } - if (MachO && Disassemble) { + if (MachOOpt && Disassemble) { DisassembleInputMachO(file); return; } -- cgit v1.2.3-70-g09d2 From ef8581479e58fe092178a9727f373a61b690a8df Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 13 Dec 2012 06:36:18 +0000 Subject: Revert "Add a funciton to get the segment name of a section." This reverts commit r170095 since it appears to be breaking the bots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170105 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 5 ----- lib/Object/MachOObjectFile.cpp | 35 ++++++++++------------------------- tools/llvm-objdump/MachODump.cpp | 8 +------- tools/llvm-objdump/llvm-objdump.cpp | 14 +++----------- 4 files changed, 14 insertions(+), 48 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index ed7aabd2c8..da972a2433 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -44,11 +44,6 @@ public: virtual unsigned getArch() const; virtual StringRef getLoadName() const; - // In a MachO file, sections have a segment name. This is used in the .o - // files. They have a single segment, but this field specifies which segment - // a section should be put in in the final object. - error_code getSectionFinalSegmentName(DataRefImpl Sec, StringRef &Res) const; - MachOObject *getObject() { return MachOObj.get(); } static inline bool classof(const Binary *v) { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 392563ad19..a38fac78aa 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -473,43 +473,28 @@ static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) { return false; } -static StringRef parseSegmentOrSectionName(const char *P) { - if (P[15] == 0) - // Null terminated. - return P; - // Not null terminated, so this is a 16 char string. - return StringRef(P, 16); -} - error_code MachOObjectFile::getSectionName(DataRefImpl DRI, StringRef &Result) const { + // FIXME: thread safety. + static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection64(LCI, DRI.d.b, Sect); - Result = parseSegmentOrSectionName(Sect->Name); + + strcpy(result, Sect->SegmentName); + strcat(result, ","); + strcat(result, Sect->Name); } else { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection(LCI, DRI.d.b, Sect); - Result = parseSegmentOrSectionName(Sect->Name); - } - return object_error::success; -} -error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec, - StringRef &Res) const { - if (is64BitLoadCommand(MachOObj.get(), Sec)) { - LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection64(LCI, Sec.d.b, Sect); - Res = parseSegmentOrSectionName(Sect->SegmentName); - } else { - LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection(LCI, Sec.d.b, Sect); - Res = parseSegmentOrSectionName(Sect->SegmentName); + strcpy(result, Sect->SegmentName); + strcat(result, ","); + strcat(result, Sect->Name); } + Result = StringRef(result); return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index c324ff13a6..3a350382ae 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -334,15 +334,9 @@ void llvm::DisassembleInputMachO(StringRef Filename) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { StringRef SectName; if (Sections[SectIdx].getName(SectName) || - SectName != "__text") + SectName.compare("__TEXT,__text")) continue; // Skip non-text sections - StringRef SegmentName; - DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); - if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) || - SegmentName != "__TEXT") - continue; - // Insert the functions from the function starts segment into our map. uint64_t VMAddr; Sections[SectIdx].getAddress(VMAddr); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 9edcae8d6b..2838a2a2b3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -28,7 +28,6 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" -#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -73,9 +72,9 @@ static cl::opt SymbolTable("t", cl::desc("Display the symbol table")); static cl::opt -MachOOpt("macho", cl::desc("Use MachO specific object file parser")); +MachO("macho", cl::desc("Use MachO specific object file parser")); static cl::alias -MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt)); +MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachO)); cl::opt llvm::TripleName("triple", cl::desc("Target triple to disassemble for, " @@ -568,13 +567,6 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Section == o->end_sections()) outs() << "*UND*"; else { - if (const MachOObjectFile *MachO = dyn_cast(o)) { - StringRef SegmentName; - DataRefImpl DR = Section->getRawDataRefImpl(); - if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) - SegmentName = ""; - outs() << SegmentName << ","; - } StringRef SectionName; if (error(Section->getName(SectionName))) SectionName = ""; @@ -648,7 +640,7 @@ static void DumpInput(StringRef file) { return; } - if (MachOOpt && Disassemble) { + if (MachO && Disassemble) { DisassembleInputMachO(file); return; } -- cgit v1.2.3-70-g09d2 From 1c2b2f9c56c01aa1c317da4fd0234eaa1fe6e739 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Mon, 17 Dec 2012 17:59:32 +0000 Subject: Teach MachO which sections contain code git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170349 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachOFormat.h | 4 ++++ lib/MC/MCParser/DarwinAsmParser.cpp | 2 +- lib/Object/MachOObjectFile.cpp | 4 ++-- test/Object/Inputs/macho-text-sections.macho-x86_64 | Bin 0 -> 268 bytes test/Object/X86/macho-text-sections.test | 3 +++ 5 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 test/Object/Inputs/macho-text-sections.macho-x86_64 create mode 100644 test/Object/X86/macho-text-sections.test (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachOFormat.h b/include/llvm/Object/MachOFormat.h index c0f700d3c8..a17d58dae2 100644 --- a/include/llvm/Object/MachOFormat.h +++ b/include/llvm/Object/MachOFormat.h @@ -237,6 +237,10 @@ namespace macho { /// @name Section Data /// @{ + enum SectionFlags { + SF_PureInstructions = 0x80000000 + }; + struct Section { char Name[16]; char SegmentName[16]; diff --git a/lib/MC/MCParser/DarwinAsmParser.cpp b/lib/MC/MCParser/DarwinAsmParser.cpp index 20c949dbda..7b042df292 100644 --- a/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/lib/MC/MCParser/DarwinAsmParser.cpp @@ -314,7 +314,7 @@ bool DarwinAsmParser::ParseSectionSwitch(const char *Segment, Lex(); // FIXME: Arch specific. - bool isText = StringRef(Segment) == "__TEXT"; // FIXME: Hack. + bool isText = TAA & MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS; getStreamer().SwitchSection(getContext().getMachOSection( Segment, Section, TAA, StubSize, isText ? SectionKind::getText() diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a38fac78aa..40f5390a96 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -559,11 +559,11 @@ error_code MachOObjectFile::isSectionText(DataRefImpl DRI, if (is64BitLoadCommand(MachOObj.get(), DRI)) { InMemoryStruct Sect; getSection64(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } else { InMemoryStruct Sect; getSection(DRI, Sect); - Result = !strcmp(Sect->Name, "__text"); + Result = Sect->Flags & macho::SF_PureInstructions; } return object_error::success; } diff --git a/test/Object/Inputs/macho-text-sections.macho-x86_64 b/test/Object/Inputs/macho-text-sections.macho-x86_64 new file mode 100644 index 0000000000..cce203ba0d Binary files /dev/null and b/test/Object/Inputs/macho-text-sections.macho-x86_64 differ diff --git a/test/Object/X86/macho-text-sections.test b/test/Object/X86/macho-text-sections.test new file mode 100644 index 0000000000..1b697dcada --- /dev/null +++ b/test/Object/X86/macho-text-sections.test @@ -0,0 +1,3 @@ +RUN: llvm-objdump -disassemble %p/../Inputs/macho-text-sections.macho-x86_64 | FileCheck %s + +CHECK: Disassembly of section __notext,__notext -- cgit v1.2.3-70-g09d2 From f9a6bd8524ba16d3e4036304ffdc9475df6844f2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 19 Dec 2012 14:15:04 +0000 Subject: Add r170095 back. I cannot reproduce it the failures locally, so I will keep an eye at the ppc bots. This patch does add the change to the "Disassembly of section" message, but that is not what was failing on the bots. Original message: Add a funciton to get the segment name of a section. On MachO, sections also have segment names. When a tool looking at a .o file prints a segment name, this is what they mean. In reality, a .o has only one anonymous, segment. This patch adds a MachO only function to fetch that segment name. I named it getSectionFinalSegmentName since the main use for the name seems to be infor the linker with segment this section should go to. The patch also changes MachOObjectFile::getSectionName to return just the section name instead of computing SegmentName,SectionName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170545 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 5 +++++ lib/Object/MachOObjectFile.cpp | 35 +++++++++++++++++++++++++---------- tools/llvm-objdump/MachODump.cpp | 8 +++++++- tools/llvm-objdump/llvm-objdump.cpp | 25 +++++++++++++++++++++---- 4 files changed, 58 insertions(+), 15 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index da972a2433..ed7aabd2c8 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -44,6 +44,11 @@ public: virtual unsigned getArch() const; virtual StringRef getLoadName() const; + // In a MachO file, sections have a segment name. This is used in the .o + // files. They have a single segment, but this field specifies which segment + // a section should be put in in the final object. + error_code getSectionFinalSegmentName(DataRefImpl Sec, StringRef &Res) const; + MachOObject *getObject() { return MachOObj.get(); } static inline bool classof(const Binary *v) { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 40f5390a96..3e29b2f9a4 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -473,28 +473,43 @@ static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) { return false; } +static StringRef parseSegmentOrSectionName(const char *P) { + if (P[15] == 0) + // Null terminated. + return P; + // Not null terminated, so this is a 16 char string. + return StringRef(P, 16); +} + error_code MachOObjectFile::getSectionName(DataRefImpl DRI, StringRef &Result) const { - // FIXME: thread safety. - static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection64(LCI, DRI.d.b, Sect); - - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); + Result = parseSegmentOrSectionName(Sect->Name); } else { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection(LCI, DRI.d.b, Sect); + Result = parseSegmentOrSectionName(Sect->Name); + } + return object_error::success; +} - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); +error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec, + StringRef &Res) const { + if (is64BitLoadCommand(MachOObj.get(), Sec)) { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + InMemoryStruct Sect; + MachOObj->ReadSection64(LCI, Sec.d.b, Sect); + Res = parseSegmentOrSectionName(Sect->SegmentName); + } else { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + InMemoryStruct Sect; + MachOObj->ReadSection(LCI, Sec.d.b, Sect); + Res = parseSegmentOrSectionName(Sect->SegmentName); } - Result = StringRef(result); return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3a350382ae..c324ff13a6 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -334,9 +334,15 @@ void llvm::DisassembleInputMachO(StringRef Filename) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { StringRef SectName; if (Sections[SectIdx].getName(SectName) || - SectName.compare("__TEXT,__text")) + SectName != "__text") continue; // Skip non-text sections + StringRef SegmentName; + DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); + if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) || + SegmentName != "__TEXT") + continue; + // Insert the functions from the function starts segment into our map. uint64_t VMAddr; Sections[SectIdx].getAddress(VMAddr); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 2838a2a2b3..24dc9c91a3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -28,6 +28,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -72,9 +73,9 @@ static cl::opt SymbolTable("t", cl::desc("Display the symbol table")); static cl::opt -MachO("macho", cl::desc("Use MachO specific object file parser")); +MachOOpt("macho", cl::desc("Use MachO specific object file parser")); static cl::alias -MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachO)); +MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt)); cl::opt llvm::TripleName("triple", cl::desc("Target triple to disassemble for, " @@ -241,9 +242,18 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Sort relocations by address. std::sort(Rels.begin(), Rels.end(), RelocAddressLess); + StringRef SegmentName = ""; + if (const MachOObjectFile *MachO = dyn_cast(Obj)) { + DataRefImpl DR = i->getRawDataRefImpl(); + if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) + break; + } StringRef name; if (error(i->getName(name))) break; - outs() << "Disassembly of section " << name << ':'; + outs() << "Disassembly of section "; + if (!SegmentName.empty()) + outs() << SegmentName << ","; + outs() << name << ':'; // If the section has no symbols just insert a dummy one and disassemble // the whole section. @@ -567,6 +577,13 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Section == o->end_sections()) outs() << "*UND*"; else { + if (const MachOObjectFile *MachO = dyn_cast(o)) { + StringRef SegmentName; + DataRefImpl DR = Section->getRawDataRefImpl(); + if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) + SegmentName = ""; + outs() << SegmentName << ","; + } StringRef SectionName; if (error(Section->getName(SectionName))) SectionName = ""; @@ -640,7 +657,7 @@ static void DumpInput(StringRef file) { return; } - if (MachO && Disassemble) { + if (MachOOpt && Disassemble) { DisassembleInputMachO(file); return; } -- cgit v1.2.3-70-g09d2 From cd7ee1ced017d7a957113df9d6cf855ecbc3797e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 19 Dec 2012 14:48:05 +0000 Subject: Revert 170545 while I debug the ppc failures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170547 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 5 ----- lib/Object/MachOObjectFile.cpp | 35 ++++++++++------------------------- tools/llvm-objdump/MachODump.cpp | 8 +------- tools/llvm-objdump/llvm-objdump.cpp | 25 ++++--------------------- 4 files changed, 15 insertions(+), 58 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index ed7aabd2c8..da972a2433 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -44,11 +44,6 @@ public: virtual unsigned getArch() const; virtual StringRef getLoadName() const; - // In a MachO file, sections have a segment name. This is used in the .o - // files. They have a single segment, but this field specifies which segment - // a section should be put in in the final object. - error_code getSectionFinalSegmentName(DataRefImpl Sec, StringRef &Res) const; - MachOObject *getObject() { return MachOObj.get(); } static inline bool classof(const Binary *v) { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 3e29b2f9a4..40f5390a96 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -473,43 +473,28 @@ static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) { return false; } -static StringRef parseSegmentOrSectionName(const char *P) { - if (P[15] == 0) - // Null terminated. - return P; - // Not null terminated, so this is a 16 char string. - return StringRef(P, 16); -} - error_code MachOObjectFile::getSectionName(DataRefImpl DRI, StringRef &Result) const { + // FIXME: thread safety. + static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection64(LCI, DRI.d.b, Sect); - Result = parseSegmentOrSectionName(Sect->Name); + + strcpy(result, Sect->SegmentName); + strcat(result, ","); + strcat(result, Sect->Name); } else { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); InMemoryStruct Sect; MachOObj->ReadSection(LCI, DRI.d.b, Sect); - Result = parseSegmentOrSectionName(Sect->Name); - } - return object_error::success; -} -error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec, - StringRef &Res) const { - if (is64BitLoadCommand(MachOObj.get(), Sec)) { - LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection64(LCI, Sec.d.b, Sect); - Res = parseSegmentOrSectionName(Sect->SegmentName); - } else { - LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection(LCI, Sec.d.b, Sect); - Res = parseSegmentOrSectionName(Sect->SegmentName); + strcpy(result, Sect->SegmentName); + strcat(result, ","); + strcat(result, Sect->Name); } + Result = StringRef(result); return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index c324ff13a6..3a350382ae 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -334,15 +334,9 @@ void llvm::DisassembleInputMachO(StringRef Filename) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { StringRef SectName; if (Sections[SectIdx].getName(SectName) || - SectName != "__text") + SectName.compare("__TEXT,__text")) continue; // Skip non-text sections - StringRef SegmentName; - DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); - if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) || - SegmentName != "__TEXT") - continue; - // Insert the functions from the function starts segment into our map. uint64_t VMAddr; Sections[SectIdx].getAddress(VMAddr); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 24dc9c91a3..2838a2a2b3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -28,7 +28,6 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" -#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -73,9 +72,9 @@ static cl::opt SymbolTable("t", cl::desc("Display the symbol table")); static cl::opt -MachOOpt("macho", cl::desc("Use MachO specific object file parser")); +MachO("macho", cl::desc("Use MachO specific object file parser")); static cl::alias -MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt)); +MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachO)); cl::opt llvm::TripleName("triple", cl::desc("Target triple to disassemble for, " @@ -242,18 +241,9 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Sort relocations by address. std::sort(Rels.begin(), Rels.end(), RelocAddressLess); - StringRef SegmentName = ""; - if (const MachOObjectFile *MachO = dyn_cast(Obj)) { - DataRefImpl DR = i->getRawDataRefImpl(); - if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) - break; - } StringRef name; if (error(i->getName(name))) break; - outs() << "Disassembly of section "; - if (!SegmentName.empty()) - outs() << SegmentName << ","; - outs() << name << ':'; + outs() << "Disassembly of section " << name << ':'; // If the section has no symbols just insert a dummy one and disassemble // the whole section. @@ -577,13 +567,6 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Section == o->end_sections()) outs() << "*UND*"; else { - if (const MachOObjectFile *MachO = dyn_cast(o)) { - StringRef SegmentName; - DataRefImpl DR = Section->getRawDataRefImpl(); - if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) - SegmentName = ""; - outs() << SegmentName << ","; - } StringRef SectionName; if (error(Section->getName(SectionName))) SectionName = ""; @@ -657,7 +640,7 @@ static void DumpInput(StringRef file) { return; } - if (MachOOpt && Disassemble) { + if (MachO && Disassemble) { DisassembleInputMachO(file); return; } -- cgit v1.2.3-70-g09d2 From cef81b37c77978cd4dddb4a5ad13564793ded155 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 21 Dec 2012 03:47:03 +0000 Subject: Add a function to get the segment name of a section. On MachO, sections also have segment names. When a tool looking at a .o file prints a segment name, this is what they mean. In reality, a .o has only one anonymous, segment. This patch adds a MachO only function to fetch that segment name. I named it getSectionFinalSegmentName since the main use for the name seems to be inform the linker with segment this section should go to. The patch also changes MachOObjectFile::getSectionName to return just the section name instead of computing SegmentName,SectionName. The main difference from the previous patch is that it doesn't use InMemoryStruct. It is extremely dangerous: if the endians match it returns a pointer to the file buffer, if not, it returns a pointer to an internal buffer that is overwritten in the next API call. We should change all of this code to use support::detail::packed_endian_specific_integral like ELF, but since these functions only handle strings, they work with big and little endian machines as is. I have tested this by installing ubuntu 12.10 ppc on qemu, that is why it took so long :-) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170838 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 5 ++++ lib/Object/MachOObjectFile.cpp | 55 +++++++++++++++++++++++++++---------- tools/llvm-objdump/MachODump.cpp | 8 +++++- tools/llvm-objdump/llvm-objdump.cpp | 25 ++++++++++++++--- 4 files changed, 74 insertions(+), 19 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index da972a2433..ed7aabd2c8 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -44,6 +44,11 @@ public: virtual unsigned getArch() const; virtual StringRef getLoadName() const; + // In a MachO file, sections have a segment name. This is used in the .o + // files. They have a single segment, but this field specifies which segment + // a section should be put in in the final object. + error_code getSectionFinalSegmentName(DataRefImpl Sec, StringRef &Res) const; + MachOObject *getObject() { return MachOObj.get(); } static inline bool classof(const Binary *v) { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 40f5390a96..0ad8893400 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -473,28 +473,55 @@ static bool is64BitLoadCommand(const MachOObject *MachOObj, DataRefImpl DRI) { return false; } +static StringRef parseSegmentOrSectionName(const char *P) { + if (P[15] == 0) + // Null terminated. + return P; + // Not null terminated, so this is a 16 char string. + return StringRef(P, 16); +} + error_code MachOObjectFile::getSectionName(DataRefImpl DRI, StringRef &Result) const { - // FIXME: thread safety. - static char result[34]; if (is64BitLoadCommand(MachOObj.get(), DRI)) { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection64(LCI, DRI.d.b, Sect); - - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); + unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) + + DRI.d.b * sizeof(macho::Section64); + StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64)); + const macho::Section64 *sec = + reinterpret_cast(Data.data()); + Result = parseSegmentOrSectionName(sec->Name); } else { LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(DRI.d.a); - InMemoryStruct Sect; - MachOObj->ReadSection(LCI, DRI.d.b, Sect); + unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) + + DRI.d.b * sizeof(macho::Section); + StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section)); + const macho::Section *sec = + reinterpret_cast(Data.data()); + Result = parseSegmentOrSectionName(sec->Name); + } + return object_error::success; +} - strcpy(result, Sect->SegmentName); - strcat(result, ","); - strcat(result, Sect->Name); +error_code MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec, + StringRef &Res) const { + if (is64BitLoadCommand(MachOObj.get(), Sec)) { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + unsigned SectionOffset = LCI.Offset + sizeof(macho::Segment64LoadCommand) + + Sec.d.b * sizeof(macho::Section64); + StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section64)); + const macho::Section64 *sec = + reinterpret_cast(Data.data()); + Res = parseSegmentOrSectionName(sec->SegmentName); + } else { + LoadCommandInfo LCI = MachOObj->getLoadCommandInfo(Sec.d.a); + unsigned SectionOffset = LCI.Offset + sizeof(macho::SegmentLoadCommand) + + Sec.d.b * sizeof(macho::Section); + StringRef Data = MachOObj->getData(SectionOffset, sizeof(macho::Section)); + const macho::Section *sec = + reinterpret_cast(Data.data()); + Res = parseSegmentOrSectionName(sec->SegmentName); } - Result = StringRef(result); return object_error::success; } diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3a350382ae..c324ff13a6 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -334,9 +334,15 @@ void llvm::DisassembleInputMachO(StringRef Filename) { for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) { StringRef SectName; if (Sections[SectIdx].getName(SectName) || - SectName.compare("__TEXT,__text")) + SectName != "__text") continue; // Skip non-text sections + StringRef SegmentName; + DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl(); + if (MachOOF->getSectionFinalSegmentName(DR, SegmentName) || + SegmentName != "__TEXT") + continue; + // Insert the functions from the function starts segment into our map. uint64_t VMAddr; Sections[SectIdx].getAddress(VMAddr); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 2838a2a2b3..24dc9c91a3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -28,6 +28,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/MachO.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -72,9 +73,9 @@ static cl::opt SymbolTable("t", cl::desc("Display the symbol table")); static cl::opt -MachO("macho", cl::desc("Use MachO specific object file parser")); +MachOOpt("macho", cl::desc("Use MachO specific object file parser")); static cl::alias -MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachO)); +MachOm("m", cl::desc("Alias for --macho"), cl::aliasopt(MachOOpt)); cl::opt llvm::TripleName("triple", cl::desc("Target triple to disassemble for, " @@ -241,9 +242,18 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Sort relocations by address. std::sort(Rels.begin(), Rels.end(), RelocAddressLess); + StringRef SegmentName = ""; + if (const MachOObjectFile *MachO = dyn_cast(Obj)) { + DataRefImpl DR = i->getRawDataRefImpl(); + if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) + break; + } StringRef name; if (error(i->getName(name))) break; - outs() << "Disassembly of section " << name << ':'; + outs() << "Disassembly of section "; + if (!SegmentName.empty()) + outs() << SegmentName << ","; + outs() << name << ':'; // If the section has no symbols just insert a dummy one and disassemble // the whole section. @@ -567,6 +577,13 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Section == o->end_sections()) outs() << "*UND*"; else { + if (const MachOObjectFile *MachO = dyn_cast(o)) { + StringRef SegmentName; + DataRefImpl DR = Section->getRawDataRefImpl(); + if (error(MachO->getSectionFinalSegmentName(DR, SegmentName))) + SegmentName = ""; + outs() << SegmentName << ","; + } StringRef SectionName; if (error(Section->getName(SectionName))) SectionName = ""; @@ -640,7 +657,7 @@ static void DumpInput(StringRef file) { return; } - if (MachO && Disassemble) { + if (MachOOpt && Disassemble) { DisassembleInputMachO(file); return; } -- cgit v1.2.3-70-g09d2 From 133f6b8582f12ab4fdaee3b870d4bcb12d61ca9b Mon Sep 17 00:00:00 2001 From: Jim Grosbach Date: Thu, 31 Jan 2013 19:46:57 +0000 Subject: Object: Fix errant fallthrough. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174079 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 0ad8893400..a8536184b7 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1076,6 +1076,7 @@ error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel, printRelocationTargetName(RENext, fmt); fmt << "-"; printRelocationTargetName(RE, fmt); + break; } case macho::RIT_X86_64_TLV: printRelocationTargetName(RE, fmt); -- cgit v1.2.3-70-g09d2 From 87d0b9ed1462705dd9bf1cb7f67d0bf03af776c8 Mon Sep 17 00:00:00 2001 From: Guy Benyei Date: Tue, 12 Feb 2013 21:21:59 +0000 Subject: Add static cast to unsigned char whenever a character classification function is called with a signed char argument, in order to avoid assertions in Windows Debug configuration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175006 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLLexer.cpp | 74 +++++++++++++++++------------ lib/CodeGen/SelectionDAG/TargetLowering.cpp | 2 +- lib/CodeGen/TargetInstrInfo.cpp | 2 +- lib/IR/AsmWriter.cpp | 11 +++-- lib/IR/InlineAsm.cpp | 4 +- lib/IR/LLVMContext.cpp | 5 +- lib/Linker/LinkModules.cpp | 3 +- lib/MC/MCParser/AsmParser.cpp | 9 ++-- lib/MC/MCSectionMachO.cpp | 4 +- lib/Object/COFFObjectFile.cpp | 2 +- lib/Object/MachOObjectFile.cpp | 2 +- lib/Support/FileUtilities.cpp | 4 +- lib/Support/PathV2.cpp | 3 +- lib/Support/Windows/Path.inc | 2 +- lib/Support/raw_ostream.cpp | 3 +- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 2 +- tools/llvm-objdump/llvm-objdump.cpp | 2 +- utils/FileCheck/FileCheck.cpp | 2 +- 18 files changed, 80 insertions(+), 56 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 3b8b0337e5..35108af24a 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -119,7 +119,9 @@ static void UnEscapeLexed(std::string &Str) { if (BIn < EndBuffer-1 && BIn[1] == '\\') { *BOut++ = '\\'; // Two \ becomes one BIn += 2; - } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) { + } else if (BIn < EndBuffer-2 && + isxdigit(static_cast(BIn[1])) && + isxdigit(static_cast(BIn[2]))) { *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]); BIn += 3; // Skip over handled chars ++BOut; @@ -135,7 +137,8 @@ static void UnEscapeLexed(std::string &Str) { /// isLabelChar - Return true for [-a-zA-Z$._0-9]. static bool isLabelChar(char C) { - return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_'; + return isalnum(static_cast(C)) || C == '-' || C == '$' || + C == '.' || C == '_'; } @@ -188,7 +191,7 @@ lltok::Kind LLLexer::LexToken() { switch (CurChar) { default: // Handle letters: [a-zA-Z_] - if (isalpha(CurChar) || CurChar == '_') + if (isalpha(static_cast(CurChar)) || CurChar == '_') return LexIdentifier(); return lltok::Error; @@ -282,8 +285,8 @@ lltok::Kind LLLexer::LexAt() { return lltok::GlobalVar; // Handle GlobalVarID: @[0-9]+ - if (isdigit(CurPtr[0])) { - for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) + if (isdigit(static_cast(CurPtr[0]))) { + for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr) /*empty*/; uint64_t Val = atoull(TokStart+1, CurPtr); @@ -317,10 +320,12 @@ lltok::Kind LLLexer::ReadString(lltok::Kind kind) { /// ReadVarName - Read the rest of a token containing a variable name. bool LLLexer::ReadVarName() { const char *NameStart = CurPtr; - if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' || + if (isalpha(static_cast(CurPtr[0])) || + CurPtr[0] == '-' || CurPtr[0] == '$' || CurPtr[0] == '.' || CurPtr[0] == '_') { ++CurPtr; - while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' || + while (isalnum(static_cast(CurPtr[0])) || + CurPtr[0] == '-' || CurPtr[0] == '$' || CurPtr[0] == '.' || CurPtr[0] == '_') ++CurPtr; @@ -346,8 +351,8 @@ lltok::Kind LLLexer::LexPercent() { return lltok::LocalVar; // Handle LocalVarID: %[0-9]+ - if (isdigit(CurPtr[0])) { - for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) + if (isdigit(static_cast(CurPtr[0]))) { + for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr) /*empty*/; uint64_t Val = atoull(TokStart+1, CurPtr); @@ -381,10 +386,12 @@ lltok::Kind LLLexer::LexQuote() { /// ! lltok::Kind LLLexer::LexExclaim() { // Lex a metadata name as a MetadataVar. - if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' || + if (isalpha(static_cast(CurPtr[0])) || + CurPtr[0] == '-' || CurPtr[0] == '$' || CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') { ++CurPtr; - while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' || + while (isalnum(static_cast(CurPtr[0])) || + CurPtr[0] == '-' || CurPtr[0] == '$' || CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') ++CurPtr; @@ -399,8 +406,8 @@ lltok::Kind LLLexer::LexExclaim() { /// AttrGrpID ::= #[0-9]+ lltok::Kind LLLexer::LexHash() { // Handle AttrGrpID: #[0-9]+ - if (isdigit(CurPtr[0])) { - for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) + if (isdigit(static_cast(CurPtr[0]))) { + for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr) /*empty*/; uint64_t Val = atoull(TokStart+1, CurPtr); @@ -425,8 +432,11 @@ lltok::Kind LLLexer::LexIdentifier() { for (; isLabelChar(*CurPtr); ++CurPtr) { // If we decide this is an integer, remember the end of the sequence. - if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr; - if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr; + if (!IntEnd && !isdigit(static_cast(*CurPtr))) + IntEnd = CurPtr; + if (!KeywordEnd && !isalnum(static_cast(*CurPtr)) && + *CurPtr != '_') + KeywordEnd = CurPtr; } // If we stopped due to a colon, this really is a label. @@ -676,7 +686,8 @@ lltok::Kind LLLexer::LexIdentifier() { // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by // the CFE to avoid forcing it to deal with 64-bit numbers. if ((TokStart[0] == 'u' || TokStart[0] == 's') && - TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) { + TokStart[1] == '0' && TokStart[2] == 'x' && + isxdigit(static_cast(TokStart[3]))) { int len = CurPtr-TokStart-3; uint32_t bits = len * 4; APInt Tmp(bits, StringRef(TokStart+3, len), 16); @@ -716,13 +727,13 @@ lltok::Kind LLLexer::Lex0x() { Kind = 'J'; } - if (!isxdigit(CurPtr[0])) { + if (!isxdigit(static_cast(CurPtr[0]))) { // Bad token, return it as an error. CurPtr = TokStart+1; return lltok::Error; } - while (isxdigit(CurPtr[0])) + while (isxdigit(static_cast(CurPtr[0]))) ++CurPtr; if (Kind == 'J') { @@ -769,7 +780,8 @@ lltok::Kind LLLexer::Lex0x() { /// HexPPC128Constant 0xM[0-9A-Fa-f]+ lltok::Kind LLLexer::LexDigitOrNegative() { // If the letter after the negative is not a number, this is probably a label. - if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) { + if (!isdigit(static_cast(TokStart[0])) && + !isdigit(static_cast(CurPtr[0]))) { // Okay, this is not a number after the -, it's probably a label. if (const char *End = isLabelTail(CurPtr)) { StrVal.assign(TokStart, End-1); @@ -783,7 +795,7 @@ lltok::Kind LLLexer::LexDigitOrNegative() { // At this point, it is either a label, int or fp constant. // Skip digits, we have at least one. - for (; isdigit(CurPtr[0]); ++CurPtr) + for (; isdigit(static_cast(CurPtr[0])); ++CurPtr) /*empty*/; // Check to see if this really is a label afterall, e.g. "-1:". @@ -820,13 +832,14 @@ lltok::Kind LLLexer::LexDigitOrNegative() { ++CurPtr; // Skip over [0-9]*([eE][-+]?[0-9]+)? - while (isdigit(CurPtr[0])) ++CurPtr; + while (isdigit(static_cast(CurPtr[0]))) ++CurPtr; if (CurPtr[0] == 'e' || CurPtr[0] == 'E') { - if (isdigit(CurPtr[1]) || - ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) { + if (isdigit(static_cast(CurPtr[1])) || + ((CurPtr[1] == '-' || CurPtr[1] == '+') && + isdigit(static_cast(CurPtr[2])))) { CurPtr += 2; - while (isdigit(CurPtr[0])) ++CurPtr; + while (isdigit(static_cast(CurPtr[0]))) ++CurPtr; } } @@ -838,11 +851,11 @@ lltok::Kind LLLexer::LexDigitOrNegative() { lltok::Kind LLLexer::LexPositive() { // If the letter after the negative is a number, this is probably not a // label. - if (!isdigit(CurPtr[0])) + if (!isdigit(static_cast(CurPtr[0]))) return lltok::Error; // Skip digits. - for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr) + for (++CurPtr; isdigit(static_cast(CurPtr[0])); ++CurPtr) /*empty*/; // At this point, we need a '.'. @@ -854,13 +867,14 @@ lltok::Kind LLLexer::LexPositive() { ++CurPtr; // Skip over [0-9]*([eE][-+]?[0-9]+)? - while (isdigit(CurPtr[0])) ++CurPtr; + while (isdigit(static_cast(CurPtr[0]))) ++CurPtr; if (CurPtr[0] == 'e' || CurPtr[0] == 'E') { - if (isdigit(CurPtr[1]) || - ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) { + if (isdigit(static_cast(CurPtr[1])) || + ((CurPtr[1] == '-' || CurPtr[1] == '+') && + isdigit(static_cast(CurPtr[2])))) { CurPtr += 2; - while (isdigit(CurPtr[0])) ++CurPtr; + while (isdigit(static_cast(CurPtr[0]))) ++CurPtr; } } diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 86949a7556..f5fc66c4d3 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -2038,7 +2038,7 @@ getRegForInlineAsmConstraint(const std::string &Constraint, /// a matching constraint like "4". bool TargetLowering::AsmOperandInfo::isMatchingInputConstraint() const { assert(!ConstraintCode.empty() && "No known constraint!"); - return isdigit(ConstraintCode[0]); + return isdigit(static_cast(ConstraintCode[0])); } /// getMatchedOperand - If this is an input matching constraint, this method diff --git a/lib/CodeGen/TargetInstrInfo.cpp b/lib/CodeGen/TargetInstrInfo.cpp index d5fbf14d27..20eb918793 100644 --- a/lib/CodeGen/TargetInstrInfo.cpp +++ b/lib/CodeGen/TargetInstrInfo.cpp @@ -80,7 +80,7 @@ unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), strlen(MAI.getSeparatorString())) == 0) atInsnStart = true; - if (atInsnStart && !std::isspace(*Str)) { + if (atInsnStart && !std::isspace(static_cast(*Str))) { Length += MAI.getMaxInstLength(); atInsnStart = false; } diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index bf893e855e..17d49ac410 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -117,7 +117,7 @@ static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) { } // Scan the name to see if it needs quotes first. - bool NeedsQuotes = isdigit(Name[0]); + bool NeedsQuotes = isdigit(static_cast(Name[0])); if (!NeedsQuotes) { for (unsigned i = 0, e = Name.size(); i != e; ++i) { // By making this unsigned, the value passed in to isalnum will always be @@ -125,7 +125,8 @@ static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) { // its implementation will assert. This situation can arise when dealing // with UTF-8 multibyte characters. unsigned char C = Name[i]; - if (!isalnum(C) && C != '-' && C != '.' && C != '_') { + if (!isalnum(static_cast(C)) && C != '-' && C != '.' && + C != '_') { NeedsQuotes = true; break; } @@ -1392,14 +1393,16 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) { if (Name.empty()) { Out << " "; } else { - if (isalpha(Name[0]) || Name[0] == '-' || Name[0] == '$' || + if (isalpha(static_cast(Name[0])) || + Name[0] == '-' || Name[0] == '$' || Name[0] == '.' || Name[0] == '_') Out << Name[0]; else Out << '\\' << hexdigit(Name[0] >> 4) << hexdigit(Name[0] & 0x0F); for (unsigned i = 1, e = Name.size(); i != e; ++i) { unsigned char C = Name[i]; - if (isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_') + if (isalnum(static_cast(C)) || C == '-' || C == '$' || + C == '.' || C == '_') Out << C; else Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); diff --git a/lib/IR/InlineAsm.cpp b/lib/IR/InlineAsm.cpp index 10d281bca8..9f2a9fea4b 100644 --- a/lib/IR/InlineAsm.cpp +++ b/lib/IR/InlineAsm.cpp @@ -151,10 +151,10 @@ bool InlineAsm::ConstraintInfo::Parse(StringRef Str, if (ConstraintEnd == E) return true; // "{foo" pCodes->push_back(std::string(I, ConstraintEnd+1)); I = ConstraintEnd+1; - } else if (isdigit(*I)) { // Matching Constraint + } else if (isdigit(static_cast(*I))) { // Matching Constraint // Maximal munch numbers. StringRef::iterator NumStart = I; - while (I != E && isdigit(*I)) + while (I != E && isdigit(static_cast(*I))) ++I; pCodes->push_back(std::string(NumStart, I)); unsigned N = atoi(pCodes->back().c_str()); diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp index 8e2bbb79ee..b73cd03ddd 100644 --- a/lib/IR/LLVMContext.cpp +++ b/lib/IR/LLVMContext.cpp @@ -130,12 +130,13 @@ static bool isValidName(StringRef MDName) { if (MDName.empty()) return false; - if (!std::isalpha(MDName[0])) + if (!std::isalpha(static_cast(MDName[0]))) return false; for (StringRef::iterator I = MDName.begin() + 1, E = MDName.end(); I != E; ++I) { - if (!std::isalnum(*I) && *I != '_' && *I != '-' && *I != '.') + if (!std::isalnum(static_cast(*I)) && *I != '_' && + *I != '-' && *I != '.') return false; } return true; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 3b8928a324..c358a0ad72 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -606,7 +606,8 @@ void ModuleLinker::computeTypeMapping() { // Check to see if there is a dot in the name followed by a digit. size_t DotPos = ST->getName().rfind('.'); if (DotPos == 0 || DotPos == StringRef::npos || - ST->getName().back() == '.' || !isdigit(ST->getName()[DotPos+1])) + ST->getName().back() == '.' || + !isdigit(static_cast(ST->getName()[DotPos+1]))) continue; // Check to see if the destination module has a struct with the prefix name. diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index c01ea33f64..bd2c65e646 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -1622,7 +1622,8 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { // we can't do that. AsmLexer.cpp should probably be changed to handle // '@' as a special case when needed. static bool isIdentifierChar(char c) { - return isalnum(c) || c == '_' || c == '$' || c == '.'; + return isalnum(static_cast(c)) || c == '_' || c == '$' || + c == '.'; } bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body, @@ -1646,7 +1647,8 @@ bool AsmParser::expandMacro(raw_svector_ostream &OS, StringRef Body, continue; char Next = Body[Pos + 1]; - if (Next == '$' || Next == 'n' || isdigit(Next)) + if (Next == '$' || Next == 'n' || + isdigit(static_cast(Next))) break; } else { // This macro has parameters, look for \foo, \bar, etc. @@ -3094,7 +3096,8 @@ void AsmParser::CheckForBadMacro(SMLoc DirectiveLoc, StringRef Name, if (Body[Pos] != '$' || Pos + 1 == End) continue; char Next = Body[Pos + 1]; - if (Next == '$' || Next == 'n' || isdigit(Next)) + if (Next == '$' || Next == 'n' || + isdigit(static_cast(Next))) break; } diff --git a/lib/MC/MCSectionMachO.cpp b/lib/MC/MCSectionMachO.cpp index e771556262..fc323155be 100644 --- a/lib/MC/MCSectionMachO.cpp +++ b/lib/MC/MCSectionMachO.cpp @@ -165,9 +165,9 @@ bool MCSectionMachO::isVirtualSection() const { /// StripSpaces - This removes leading and trailing spaces from the StringRef. static void StripSpaces(StringRef &Str) { - while (!Str.empty() && isspace(Str[0])) + while (!Str.empty() && isspace(static_cast(Str[0]))) Str = Str.substr(1); - while (!Str.empty() && isspace(Str.back())) + while (!Str.empty() && isspace(static_cast(Str.back()))) Str = Str.substr(0, Str.size()-1); } diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 0b7ee34c09..ca90e0e3c3 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -267,7 +267,7 @@ error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb, } if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL) - ret = ::toupper(ret); + ret = ::toupper(static_cast(ret)); Result = ret; return object_error::success; diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index a8536184b7..eb1690e659 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -273,7 +273,7 @@ error_code MachOObjectFile::getSymbolNMTypeChar(DataRefImpl DRI, } if (Flags & (macho::STF_External | macho::STF_PrivateExtern)) - Char = toupper(Char); + Char = toupper(static_cast(Char)); Result = Char; return object_error::success; } diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp index fc8a2f31bd..4d7b2391f0 100644 --- a/lib/Support/FileUtilities.cpp +++ b/lib/Support/FileUtilities.cpp @@ -87,9 +87,9 @@ static bool CompareNumbers(const char *&F1P, const char *&F2P, // If one of the positions is at a space and the other isn't, chomp up 'til // the end of the space. - while (isspace(*F1P) && F1P != F1End) + while (isspace(static_cast(*F1P)) && F1P != F1End) ++F1P; - while (isspace(*F2P) && F2P != F2End) + while (isspace(static_cast(*F2P)) && F2P != F2End) ++F2P; // If we stop on numbers, compare their difference. diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 98d7382b4e..41add96194 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -44,7 +44,8 @@ namespace { #ifdef LLVM_ON_WIN32 // C: - if (path.size() >= 2 && std::isalpha(path[0]) && path[1] == ':') + if (path.size() >= 2 && std::isalpha(static_cast(path[0])) && + path[1] == ':') return path.substr(0, 2); #endif diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 98d8a1850b..f4898e619a 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -82,7 +82,7 @@ Path::isValid() const { pos = path.rfind(':',len); size_t rootslash = 0; if (pos != std::string::npos) { - if (pos != 1 || !isalpha(path[0]) || len < 3) + if (pos != 1 || !isalpha(static_cast(path[0])) || len < 3) return false; rootslash = 2; } diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 106864dd05..f71abd3b24 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -241,7 +241,8 @@ raw_ostream &raw_ostream::operator<<(double N) { if (cs == '+' || cs == '-') { int c1 = buf[len - 2]; int c0 = buf[len - 1]; - if (isdigit(c1) && isdigit(c0)) { + if (isdigit(static_cast(c1)) && + isdigit(static_cast(c0))) { // Trim leading '0': "...e+012" -> "...e+12\0" buf[len - 3] = c1; buf[len - 2] = c0; diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 2ec85918c1..99479a46a8 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -450,7 +450,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, outs() << " blob data = "; bool BlobIsPrintable = true; for (unsigned i = 0, e = Blob.size(); i != e; ++i) - if (!isprint(Blob[i])) { + if (!isprint(static_cast(Blob[i]))) { BlobIsPrintable = false; break; } diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 95f7690ce5..322bd21b28 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -481,7 +481,7 @@ static void PrintSectionContents(const ObjectFile *o) { // Print ascii. outs() << " "; for (std::size_t i = 0; i < 16 && addr + i < end; ++i) { - if (std::isprint(Contents[addr + i] & 0xFF)) + if (std::isprint(static_cast(Contents[addr + i]) & 0xFF)) outs() << Contents[addr + i]; else outs() << "."; diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 74442ec144..563cab0d5d 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -242,7 +242,7 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM, } // Name can't start with a digit. - if (isdigit(Name[0])) { + if (isdigit(static_cast(Name[0]))) { SM.PrintMessage(SMLoc::getFromPointer(Name.data()), SourceMgr::DK_Error, "invalid name in named regex"); return true; -- cgit v1.2.3-70-g09d2 From b3e6b04aea9d12183b97770f7b250622e78fe7f1 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 28 Feb 2013 20:26:17 +0000 Subject: Move an assert earlier in a file and check that the result of our bitwise compare is equal to the field we're looking for. Noticed on inspection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176296 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index eb1690e659..6501df9fb9 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1304,14 +1304,17 @@ StringRef MachOObjectFile::getFileFormatName() const { } } + // Make sure the cpu type has the correct mask. + assert((MachOObj->getHeader().CPUType & llvm::MachO::CPUArchABI64) + == llvm::MachO::CPUArchABI64 && + "32-bit object file when we're 64-bit?"); + switch (MachOObj->getHeader().CPUType) { case llvm::MachO::CPUTypeX86_64: return "Mach-O 64-bit x86-64"; case llvm::MachO::CPUTypePowerPC64: return "Mach-O 64-bit ppc64"; default: - assert((MachOObj->getHeader().CPUType & llvm::MachO::CPUArchABI64) == 1 && - "32-bit object file when we're 64-bit?"); return "Mach-O 64-bit unknown"; } } -- cgit v1.2.3-70-g09d2