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-18-g5258 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 --- lib/Object/MachOObjectFile.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') 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; } -- cgit v1.2.3-18-g5258 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 --- lib/Object/MachOObjectFile.cpp | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') 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; } -- cgit v1.2.3-18-g5258 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 --- lib/Object/MachOObjectFile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/Object/MachOObjectFile.cpp') 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; } -- cgit v1.2.3-18-g5258