[llvm] [JITLink][XCOFF] Setup initial build support for XCOFF (PR #127266)

Henry Jiang via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 7 08:24:17 PST 2025


================
@@ -227,6 +229,47 @@ getCOFFObjectFileSymbolInfo(ExecutionSession &ES,
   return I;
 }
 
+Expected<MaterializationUnit::Interface>
+getXCOFFObjectFileSymbolInfo(ExecutionSession &ES,
+                             const object::ObjectFile &Obj) {
+
+  MaterializationUnit::Interface I;
+
+  for (auto &Sym : Obj.symbols()) {
+    Expected<uint32_t> SymFlagsOrErr = Sym.getFlags();
+    if (!SymFlagsOrErr)
+      return SymFlagsOrErr.takeError();
+    uint32_t Flags = *SymFlagsOrErr;
+
+    // Skip undefined, non global and ST_File
+    if (Flags & object::SymbolRef::SF_Undefined)
+      continue;
+    if (!(Flags & object::SymbolRef::SF_Global))
+      continue;
+
+    auto SymbolType = Sym.getType();
+    if (!SymbolType)
+      return SymbolType.takeError();
+
+    if (*SymbolType == object::SymbolRef::ST_File)
+      continue;
+
+    auto Name = Sym.getName();
+    if (!Name)
+      return Name.takeError();
+    auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
+    if (!SymFlags)
+      return SymFlags.takeError();
+
+    // TODO: Global symbols should have default visibility for now
+    *SymFlags |= JITSymbolFlags::Exported;
----------------
mustartt wrote:

Based on https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command#ld__title__13, we should be exporting `SF_Exported` based on the `ld` documentation:
> Protected	The symbol is exported but cannot be rebounded (or preempted), even if runtime linking is being used.
> Exported	The symbol is exported with the global export attribute.

Will separate this change to another patch in case of test breaks.

https://github.com/llvm/llvm-project/pull/127266


More information about the llvm-commits mailing list