mirror of
https://github.com/autc04/Retro68.git
synced 2024-11-26 22:51:01 +00:00
Elf2Mac: option for stripping macsbug symbols
This commit is contained in:
parent
70be98cb62
commit
04174d1b55
@ -98,6 +98,7 @@ int main(int argc, char *argv[])
|
|||||||
bool elf2mac = false;
|
bool elf2mac = false;
|
||||||
bool flatoutput = false;
|
bool flatoutput = false;
|
||||||
bool segments = true;
|
bool segments = true;
|
||||||
|
bool stripMacsbug = false;
|
||||||
|
|
||||||
vector<string> args2;
|
vector<string> args2;
|
||||||
for(auto p = args.begin(), e = args.end(); p != e; ++p)
|
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");
|
errx(EXIT_FAILURE, "--mac-segments missing argument");
|
||||||
//segmentMapFile = *p;
|
//segmentMapFile = *p;
|
||||||
}
|
}
|
||||||
|
else if(*p == "--mac-strip-macsbug")
|
||||||
|
{
|
||||||
|
stripMacsbug = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args2.push_back(*p);
|
args2.push_back(*p);
|
||||||
@ -151,16 +156,11 @@ int main(int argc, char *argv[])
|
|||||||
ofstream out(tmpfile);
|
ofstream out(tmpfile);
|
||||||
if(segments)
|
if(segments)
|
||||||
{
|
{
|
||||||
segmentMap.CreateLdScript(out);
|
segmentMap.CreateLdScript(out, stripMacsbug);
|
||||||
segmentMap.CreateLdScript(std::cout);
|
|
||||||
|
|
||||||
ofstream f("/tmp/foo.ld");
|
|
||||||
segmentMap.CreateLdScript(f);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CreateFlatLdScript(out);
|
CreateFlatLdScript(out, stripMacsbug);
|
||||||
CreateFlatLdScript(std::cout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,5 +194,3 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,6 @@
|
|||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
void CreateFlatLdScript(std::ostream& out);
|
void CreateFlatLdScript(std::ostream& out, bool stripMacsbug);
|
||||||
|
|
||||||
#endif // ELF2MAC_H
|
#endif // ELF2MAC_H
|
||||||
|
@ -181,10 +181,16 @@ const char * scriptEnd = R"ld(
|
|||||||
)ld";
|
)ld";
|
||||||
|
|
||||||
|
|
||||||
void CreateFlatLdScript(std::ostream& out)
|
void CreateFlatLdScript(std::ostream& out, bool stripMacsbug)
|
||||||
{
|
{
|
||||||
out << "_MULTISEG_APP = 0;\n";
|
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 << "_MULTISEG_APP = 1;\n";
|
||||||
out << scriptStart;
|
out << scriptStart;
|
||||||
|
if(stripMacsbug)
|
||||||
|
{
|
||||||
|
out << "\t.strippedmacsbugnames 0 (NOLOAD) : { *(.text.*.macsbug) }\n";
|
||||||
|
out << "\t. = 0;\n";
|
||||||
|
}
|
||||||
for(SegmentInfo& seg: segments)
|
for(SegmentInfo& seg: segments)
|
||||||
{
|
{
|
||||||
seg.CreateLdScript(out);
|
seg.CreateLdScript(out);
|
||||||
|
@ -49,8 +49,6 @@ Object::~Object()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Object::Object(string input)
|
Object::Object(string input)
|
||||||
{
|
{
|
||||||
if(elf_version ( EV_CURRENT ) == EV_NONE)
|
if(elf_version ( EV_CURRENT ) == EV_NONE)
|
||||||
@ -86,15 +84,14 @@ Object::Object(string input)
|
|||||||
gelf_getshdr(scn, &shdr);
|
gelf_getshdr(scn, &shdr);
|
||||||
std::string name = elf_strptr(elf, sectionHeaderStringTableIdx, shdr.sh_name);
|
std::string name = elf_strptr(elf, sectionHeaderStringTableIdx, shdr.sh_name);
|
||||||
//std::cout << "section #" << idx << ": " << name << std::endl;
|
//std::cout << "section #" << idx << ": " << name << std::endl;
|
||||||
|
//std::cout << " =" << shdr.sh_addr << " + " << shdr.sh_size << std::endl;
|
||||||
|
|
||||||
if(shdr.sh_type == SHT_SYMTAB
|
if(shdr.sh_type == SHT_SYMTAB
|
||||||
&& !symtab)
|
&& !symtab)
|
||||||
{
|
{
|
||||||
symtab.reset(new Symtab(*this, scn));
|
symtab.reset(new Symtab(*this, scn));
|
||||||
}
|
}
|
||||||
|
if(shdr.sh_type == SHT_RELA)
|
||||||
if(shdr.sh_type == SHT_RELA
|
|
||||||
&& !bssSection) // ignore everything after bss, that's just debug info
|
|
||||||
{
|
{
|
||||||
if(boost::algorithm::starts_with(name,".rela."))
|
if(boost::algorithm::starts_with(name,".rela."))
|
||||||
{
|
{
|
||||||
@ -103,10 +100,15 @@ Object::Object(string input)
|
|||||||
sections[progbitsName]->SetRela(scn);
|
sections[progbitsName]->SetRela(scn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(shdr.sh_type == SHT_PROGBITS
|
if(shdr.sh_type == SHT_PROGBITS && (shdr.sh_flags & SHF_ALLOC))
|
||||||
&& !bssSection) // ignore everything after bss, that's just debug info
|
|
||||||
{
|
{
|
||||||
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);
|
auto section = make_shared<Section>(*this, name, idx, kind, scn);
|
||||||
|
|
||||||
sections[name] = sectionsByElfIndex[idx] = section;
|
sections[name] = sectionsByElfIndex[idx] = section;
|
||||||
@ -117,10 +119,6 @@ Object::Object(string input)
|
|||||||
}
|
}
|
||||||
if(shdr.sh_type == SHT_NOBITS)
|
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] =
|
bssSection = sections[name] = sectionsByElfIndex[idx] =
|
||||||
make_shared<Section>(*this, name, idx, SectionKind::bss, scn);
|
make_shared<Section>(*this, name, idx, SectionKind::bss, scn);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class SegmentMap
|
|||||||
public:
|
public:
|
||||||
SegmentMap();
|
SegmentMap();
|
||||||
|
|
||||||
void CreateLdScript(std::ostream& out);
|
void CreateLdScript(std::ostream& out, bool stripMacsbug);
|
||||||
std::string GetSegmentName(int id);
|
std::string GetSegmentName(int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user