Skip to content

Commit

Permalink
Fix multisegment app with > 10 CODE resources
Browse files Browse the repository at this point in the history
Closes autc04#195
  • Loading branch information
ryandesign committed Oct 27, 2022
1 parent 280a1e4 commit caab1a7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Elf2Mac/LdScript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include "Elf2Mac.h"
#include "SegmentMap.h"

#include <iostream>
#include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>

using std::string;
Expand Down Expand Up @@ -214,7 +215,11 @@ void SegmentInfo::WriteFiltersKeep(std::ostream &out, string section)

void SegmentInfo::CreateLdScript(std::ostream &out, string entryPoint)
{
out << "\t.code" << id << " : {\n";
std::ostringstream ss;
ss << std::setw(5) << std::setfill('0') << id;
const std::string zero_padded_id = ss.str();

out << "\t.code" << zero_padded_id << " : {\n";
out << "\t\tFILL(0x4E71);\n";
if(id == 1)
{
Expand Down Expand Up @@ -259,7 +264,7 @@ void SegmentInfo::CreateLdScript(std::ostream &out, string entryPoint)
if(id == 1)
out << "\t\t__EH_FRAME_BEGIN__" << " = .;\n";
else
out << "\t\t__EH_FRAME_BEGIN__" << id << " = .;\n";
out << "\t\t__EH_FRAME_BEGIN__" << zero_padded_id << " = .;\n";
WriteFiltersKeep(out, ".eh_frame");
out << "\t\tLONG(0);\n";
WriteFiltersKeep(out, ".gcc_except_table");
Expand All @@ -278,7 +283,7 @@ void SegmentInfo::CreateLdScript(std::ostream &out, string entryPoint)
FILL(0);
. += 32;
LONG(__EH_FRAME_BEGIN__@N@ - .);
)ld", "@N@", boost::lexical_cast<string>(id));
)ld", "@N@", zero_padded_id);
}

out << "\t}\n";
Expand Down

0 comments on commit caab1a7

Please sign in to comment.