[all-commits] [llvm/llvm-project] db5e07: [LTO] Add SelectionKind to IRSymtab and use it in ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Jul 20 13:22:14 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: db5e0786900e53843f87c4169c404f8c7831eb8c
      https://github.com/llvm/llvm-project/commit/db5e0786900e53843f87c4169c404f8c7831eb8c
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-07-20 (Tue, 20 Jul 2021)

  Changed paths:
    M lld/COFF/InputFiles.cpp
    M lld/ELF/InputFiles.cpp
    A lld/test/ELF/lto/comdat-nodeduplicate.ll
    M lld/wasm/InputFiles.cpp
    M llvm/include/llvm/LTO/LTO.h
    M llvm/include/llvm/Object/IRSymtab.h
    M llvm/lib/Object/IRSymtab.cpp
    M llvm/test/LTO/Resolution/X86/symtab.ll
    M llvm/test/Object/X86/irsymtab.ll
    A llvm/test/tools/gold/X86/comdat-nodeduplicate.ll
    M llvm/tools/gold/gold-plugin.cpp
    M llvm/tools/llvm-lto2/llvm-lto2.cpp

  Log Message:
  -----------
  [LTO] Add SelectionKind to IRSymtab and use it in ld.lld/LLVMgold

In PGO, a C++ external linkage function `foo` has a private counter
`__profc_foo` and a private `__profd_foo` in a `comdat nodeduplicate`.

A `__attribute__((weak))` function `foo` has a weak hidden counter `__profc_foo`
and a private `__profd_foo` in a `comdat nodeduplicate`.

In `ld.lld a.o b.o`, say a.o defines an external linkage `foo` and b.o
defines a weak `foo`. Currently we treat `comdat nodeduplicate` as `comdat any`,
ld.lld will incorrectly consider `b.o:__profc_foo` non-prevailing.  In the worst
case when `b.o:__profd_foo` is retained and `b.o:__profc_foo` isn't, there will
be dangling reference causing an `undefined hidden symbol` error.

Add SelectionKind to `Comdat` in IRSymtab and let linkers ignore nodeduplicate comdat.

Differential Revision: https://reviews.llvm.org/D106228




More information about the All-commits mailing list