[llvm] [Demangler] support demangling for AIX function entry names (PR #67389)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 20:29:16 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

<details>
<summary>Changes</summary>

AIX has two symbols for a function, one is function descriptor and another one is function entry(there is a leading dot). See details in https://www.ibm.com/docs/en/aix/7.1?topic=formats-xcoff-object-file-format

```
a function descriptor, which contains the following three values:

    The address of the executable code for a function.
    The address of the TOC anchor (TOC base address) of the module that contains the function.
    The environment pointer (used by languages such as Pascal and PL/I).
```

A symbol table example:
```
[9]	m   0x00000060     .text     1    weak                    ._ZN1A3fooEi
[10]	a4  0x00000005       0    0     LD       PR    0    0
[13]	m   0x000000cc     .data     1    weak                    _ZN1A3fooEi
[14]	a4  0x0000000c       0    0     SD       DS    0    0
```

For now, llvm-cxxfilt is able to demangle `_ZN1A3fooEi`, but it can not demangle function entry name `._ZN1A3fooEi`.  Support demangling the function entry names as well. Sanitizers will check the function entries' demangle names in the LIT tests.

---
Full diff: https://github.com/llvm/llvm-project/pull/67389.diff


2 Files Affected:

- (modified) llvm/lib/Demangle/Demangle.cpp (+4) 
- (modified) llvm/test/tools/llvm-cxxfilt/delimiters.test (+5-1) 


``````````diff
diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp
index f2aa571d685f7a5..710cbaeca08aeeb 100644
--- a/llvm/lib/Demangle/Demangle.cpp
+++ b/llvm/lib/Demangle/Demangle.cpp
@@ -50,6 +50,10 @@ bool llvm::nonMicrosoftDemangle(std::string_view MangledName,
   char *Demangled = nullptr;
   if (isItaniumEncoding(MangledName))
     Demangled = itaniumDemangle(MangledName);
+  // AIX function entries start with '.'.
+  else if (starts_with(MangledName, '.') &&
+           isItaniumEncoding(MangledName.substr(1)))
+    Demangled = itaniumDemangle(MangledName.substr(1));
   else if (isRustEncoding(MangledName))
     Demangled = rustDemangle(MangledName);
   else if (isDLangEncoding(MangledName))
diff --git a/llvm/test/tools/llvm-cxxfilt/delimiters.test b/llvm/test/tools/llvm-cxxfilt/delimiters.test
index 9a5b690a00520de..e745d25fbe560b4 100644
--- a/llvm/test/tools/llvm-cxxfilt/delimiters.test
+++ b/llvm/test/tools/llvm-cxxfilt/delimiters.test
@@ -29,6 +29,8 @@ RUN:      '_Z3Foo}'   \
 RUN:      '_Z3Foo~,,' \
 RUN:      '_Z3Foo⦙_Z3Bar' \
 RUN:      '_Z3Foo,,_Z3Bar::_Z3Baz  _Z3Foo,_Z3Bar:_Z3Baz' \
+RUN:      '_ZN1A3fooEi' \
+RUN:      '._ZN1A3fooEi' \
 COM: Piping the echo output causes '⦙' to be converted to '?' in some
 COM: builds/environments. Redirect echo output to and from %t to work
 COM: around this. See D111072.
@@ -66,4 +68,6 @@ CHECK: Foo}
 CHECK: Foo~,,
 CHECK: Foo⦙Bar
 CHECK: Foo,,Bar::Baz  Foo,Bar:Baz
-CHECK: _Z3Foo$ ._Z3Foo
+CHECK: A::foo(int)
+CHECK: A::foo(int)
+CHECK: _Z3Foo$ Foo

``````````

</details>


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


More information about the llvm-commits mailing list