autc04 / Retro68

a gcc-based cross-compiler for classic 68K and PPC Macintoshes
GNU General Public License v3.0
537 stars 51 forks source link

Patch: export data from PowerPC code fragments #210

Closed elliotnunn closed 7 months ago

elliotnunn commented 11 months ago

I have used Retro68 to compile "ndrv" driver fragments, which export a data symbol called "TheDriverDescription".

Here is a patch to MakePEF that enables data exports. (I apologise for not making a PR -- I didn't want to fork the repo on GitHub just for this.)

diff --git a/PEFTools/MakePEF.cc b/PEFTools/MakePEF.cc
--- a/PEFTools/MakePEF.cc
+++ b/PEFTools/MakePEF.cc
@@ -227,9 +227,9 @@ class ExportTable
 public:

     void addExport(StringTable& stringTable, const std::string& name,
-        uint32_t value, int16_t section) /* TODO: symbol class */
+        uint32_t value, int16_t section, uint8_t clas)
     {
-        uint32_t classAndName = (kPEFTVectorSymbol << 24) | stringTable.insert(name);
+        uint32_t classAndName = ((uint32_t)clas << 24) | stringTable.insert(name);
         symbols.push_back({hash(name), {classAndName, value, section}});
     }

@@ -376,7 +376,9 @@ void mkpef(const std::string& inFn, const std::string& outFn)
             {
                 if(verboseFlag)
                     std::cerr << "... exported from section " << get(sym.l_scnum) << " addr " << get(sym.l_value) <<  ".\n";
-                exports.addExport(stringTable, name, get(sym.l_value), 0 /* ### */);
+                exports.addExport(stringTable, name, get(sym.l_value), 1 /*all exports from section 1*/,
+                    (get(sym.l_smclas) == 10) ? kPEFTVectorSymbol : kPEFDataSymbol);
+
             }
         }
         importedSymbolIndices.resize(get(xcoffLoaderHeader.l_nsyms));
autc04 commented 7 months ago

Finally got around to reviewing & testing this, thanks a lot!