[llvm] [llvm-symbolizer] Make symbolizer parse section relative syntax (PR #168524)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 01:50:36 PDT 2026


================
@@ -153,10 +155,92 @@ static StringRef getSpaceDelimitedWord(StringRef &Source) {
   return Result;
 }
 
+// Only TEXT and DATA section types are supported in XCOFF section-relative
+// syntax. The AIX process map (procmap) maps only TEXT and DATA. BSS is
+// allocated after the non-BSS data, so BSS symbol addresses are relative to
+// the DATA section base and do not need a separate section type. TDATA and
+// TBSS are excluded because there is no demonstrated need to symbolize
+// thread-local storage from runtime addresses. Restricting to TEXT and DATA
+// also ensures there is at most one section of each type in a loadable XCOFF
+// module, keeping section-relative addresses unambiguous.
+static std::optional<XCOFF::SectionTypeFlags>
+parseXCOFFSectionType(StringRef TypeStr) {
+  return StringSwitch<std::optional<XCOFF::SectionTypeFlags>>(TypeStr)
+      .Case("TEXT", XCOFF::STYP_TEXT)
+      .Case("DATA", XCOFF::STYP_DATA)
+      .Default(std::nullopt);
+}
+
+// Resolve a section-relative address of the form (SECTION_TYPE)(+offset) to an
+// absolute VMA for symbolization. Looks up the base address of the unique
+// section of the given type in the XCOFF object at ModulePath, then returns
+// SectionBase + Offset as the absolute VMA.
+static Expected<uint64_t>
+resolveXCOFFSectionAddress(StringRef ModulePath, StringRef SectionType,
+                           uint64_t Offset, LLVMSymbolizer &Symbolizer) {
+  std::optional<XCOFF::SectionTypeFlags> SectionTypeFlag =
+      parseXCOFFSectionType(SectionType);
+  if (!SectionTypeFlag)
+    return createStringError("unknown or unsupported section type \"" +
+                             SectionType.str() +
+                             "\" in section-relative address");
+
+  Expected<uint64_t> SectionBaseOrErr = Symbolizer.getXCOFFSectionAddress(
+      ModulePath, *SectionTypeFlag, SectionType);
+  if (!SectionBaseOrErr)
+    return SectionBaseOrErr.takeError();
+
+  return *SectionBaseOrErr + Offset;
+}
+
+// Parses (SECTION_TYPE)(+offset) syntax from AddrSpec.
+// Returns true (with SectionType and Offset set) if the syntax matches and is
+// valid; returns false if AddrSpec does not start with this syntax;
+// returns an error if the syntax is recognized but invalid.
----------------
midhuncodes7 wrote:

Fixed 

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


More information about the llvm-commits mailing list