[clang] [compiler-rt] [llvm] [clang-tools-extra] [PGO][GlobalValue][LTO]In GlobalValues::getGlobalIdentifier, use semicolon as delimiter for local-linkage varibles. (PR #74008)

Mingming Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 11 17:13:04 PST 2023


================
@@ -0,0 +1,115 @@
+// This is a regression test for ThinLTO indirect-call-promotion when candidate
+// callees need to be imported from another IR module.  In the C++ test case,
+// `main` calls `global_func` which is defined in another module. `global_func`
+// has two indirect callees, one has external linkage and one has local linkage.
+// All three functions should be imported into the IR module of main.
+
+// What the test does:
+// - Generate raw profiles from executables and convert it to indexed profiles.
+//   During the conversion, a profiled callee address in raw profiles will be
+//   converted to function hash in indexed profiles.
+// - Run IRPGO profile use and ThinTLO prelink pipeline and get LLVM bitcodes
+//   for both cpp files in the C++ test case.
+// - Generate ThinLTO summary file with LLVM bitcodes, and run `function-import` pass.
+// - Run `pgo-icall-prom` pass for the IR module which needs to import callees.
+
+// Use lld as linker for more robust test. We need to REQUIRE LLVMgold.so for
+// LTO if default linker is GNU ld or gold anyway.
+// REQUIRES: lld-available
+
+// Test should fail where linkage-name and mangled-name diverges, see issue https://github.com/llvm/llvm-project/issues/74565).
+// Currently, this name divergence happens on Mach-O object file format, or on
+// many (but not all) 32-bit Windows systems.
----------------
minglotus-6 wrote:

Some more details regarding this statement

1. The global prefix is `_` for {`MachO`, `WinCOFFX86`} and  `\0` (i.e., no prefix) for the rest of mangling modes ([source code](https://github.com/llvm/llvm-project/blob/185302530847a28f44e48a67a79fd4eba048a1c7/llvm/include/llvm/IR/DataLayout.h#L316-L328)). 
    * The global prefix is [used by IR Mangler](https://github.com/llvm/llvm-project/blob/62b21c6ced918c7fec97b557e3087e3ffdf71494/llvm/lib/IR/Mangler.cpp#L144) in global symbols (e.g., prefix [emitted](https://github.com/llvm/llvm-project/blob/62b21c6ced918c7fec97b557e3087e3ffdf71494/llvm/lib/IR/Mangler.cpp#L55-L56) if it's not `\0`)
2.  In the data-layout string,`m:o` specifies `MachO`, `m:x` specifies `WinCOFFX86`, and `m:e` specifies `ELF` ([parser source code](https://github.com/llvm/llvm-project/blob/185302530847a28f44e48a67a79fd4eba048a1c7/llvm/lib/IR/DataLayout.cpp#L510-L541)) 

With 1 and 2, note not all 32-bit windows uses `WinCOFFX86` mangling-mode. For instance, one windows-32 target [specifies](https://github.com/llvm/llvm-project/blob/a8ef9c0969ab0807672bcad60970bf22395ffaf1/clang/lib/Basic/Targets/X86.h#L672) `m:e`, and some [1] windows-32 target chooses between `m:e` and one of {`m:x`, `m:o`}

[1] [example 1](https://github.com/llvm/llvm-project/blob/a8ef9c0969ab0807672bcad60970bf22395ffaf1/clang/lib/Basic/Targets/X86.h#L581) chooses between `m:x` and `m:e`,and [example 2](https://github.com/llvm/llvm-project/blob/a8ef9c0969ab0807672bcad60970bf22395ffaf1/clang/lib/Basic/Targets/X86.h#L444-L447) chooses between `m:o` and `m:e`

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


More information about the cfe-commits mailing list