Elf2Mac: option for stripping macsbug symbols

This commit is contained in:
Wolfgang Thaller 2017-09-29 22:04:11 +02:00
parent 70be98cb62
commit 04174d1b55
5 changed files with 33 additions and 27 deletions

View File

@ -98,6 +98,7 @@ int main(int argc, char *argv[])
bool elf2mac = false;
bool flatoutput = false;
bool segments = true;
bool stripMacsbug = false;
vector<string> args2;
for(auto p = args.begin(), e = args.end(); p != e; ++p)
@ -133,6 +134,10 @@ int main(int argc, char *argv[])
errx(EXIT_FAILURE, "--mac-segments missing argument");
//segmentMapFile = *p;
}
else if(*p == "--mac-strip-macsbug")
{
stripMacsbug = true;
}
else
{
args2.push_back(*p);
@ -151,16 +156,11 @@ int main(int argc, char *argv[])
ofstream out(tmpfile);
if(segments)
{
segmentMap.CreateLdScript(out);
segmentMap.CreateLdScript(std::cout);
ofstream f("/tmp/foo.ld");
segmentMap.CreateLdScript(f);
segmentMap.CreateLdScript(out, stripMacsbug);
}
else
{
CreateFlatLdScript(out);
CreateFlatLdScript(std::cout);
CreateFlatLdScript(out, stripMacsbug);
}
}
@ -194,5 +194,3 @@ int main(int argc, char *argv[])
}
return 0;
}

View File

@ -22,6 +22,6 @@
#include <iosfwd>
void CreateFlatLdScript(std::ostream& out);
void CreateFlatLdScript(std::ostream& out, bool stripMacsbug);
#endif // ELF2MAC_H

View File

@ -181,10 +181,16 @@ const char * scriptEnd = R"ld(
)ld";
void CreateFlatLdScript(std::ostream& out)
void CreateFlatLdScript(std::ostream& out, bool stripMacsbug)
{
out << "_MULTISEG_APP = 0;\n";
out << scriptStart << textSection << scriptEnd;
out << scriptStart;
if(stripMacsbug)
{
out << "\t.strippedmacsbugnames 0 (NOLOAD) : { *(.text.*.macsbug) }\n";
out << "\t. = 0;\n";
}
out << textSection << scriptEnd;
}
@ -278,11 +284,15 @@ void SegmentInfo::CreateLdScript(std::ostream &out)
}
void SegmentMap::CreateLdScript(std::ostream &out)
void SegmentMap::CreateLdScript(std::ostream &out, bool stripMacsbug)
{
out << "_MULTISEG_APP = 1;\n";
out << scriptStart;
if(stripMacsbug)
{
out << "\t.strippedmacsbugnames 0 (NOLOAD) : { *(.text.*.macsbug) }\n";
out << "\t. = 0;\n";
}
for(SegmentInfo& seg: segments)
{
seg.CreateLdScript(out);

View File

@ -49,8 +49,6 @@ Object::~Object()
{
}
Object::Object(string input)
{
if(elf_version ( EV_CURRENT ) == EV_NONE)
@ -86,15 +84,14 @@ Object::Object(string input)
gelf_getshdr(scn, &shdr);
std::string name = elf_strptr(elf, sectionHeaderStringTableIdx, shdr.sh_name);
//std::cout << "section #" << idx << ": " << name << std::endl;
//std::cout << " =" << shdr.sh_addr << " + " << shdr.sh_size << std::endl;
if(shdr.sh_type == SHT_SYMTAB
&& !symtab)
{
symtab.reset(new Symtab(*this, scn));
}
if(shdr.sh_type == SHT_RELA
&& !bssSection) // ignore everything after bss, that's just debug info
if(shdr.sh_type == SHT_RELA)
{
if(boost::algorithm::starts_with(name,".rela."))
{
@ -103,10 +100,15 @@ Object::Object(string input)
sections[progbitsName]->SetRela(scn);
}
}
if(shdr.sh_type == SHT_PROGBITS
&& !bssSection) // ignore everything after bss, that's just debug info
if(shdr.sh_type == SHT_PROGBITS && (shdr.sh_flags & SHF_ALLOC))
{
SectionKind kind = name == ".data" ? SectionKind::data : SectionKind::code;
SectionKind kind = SectionKind::code;
if(name == ".data")
kind = SectionKind::data;
if(name == ".strippedmacsbugnames")
kind = SectionKind::undefined;
auto section = make_shared<Section>(*this, name, idx, kind, scn);
sections[name] = sectionsByElfIndex[idx] = section;
@ -117,10 +119,6 @@ Object::Object(string input)
}
if(shdr.sh_type == SHT_NOBITS)
{
// Currently, the bss section is used
// to know when to start skipping debug info sections.
// (What's the official way to distinguish a debug info section from a "real" section?)
bssSection = sections[name] = sectionsByElfIndex[idx] =
make_shared<Section>(*this, name, idx, SectionKind::bss, scn);
}

View File

@ -48,7 +48,7 @@ class SegmentMap
public:
SegmentMap();
void CreateLdScript(std::ostream& out);
void CreateLdScript(std::ostream& out, bool stripMacsbug);
std::string GetSegmentName(int id);
};