llvm-project
51 строка · 1.3 Кб
1// Check that instrprof does not introduce references to discarded sections when
2// using comdats.
3//
4// Occasionally, it is possible that the same function can be compiled in
5// different TUs with slightly different linkages, e.g., due to different
6// compiler options. However, if these are comdat functions, a single
7// implementation will be chosen at link time. we want to ensure that the
8// profiling data does not contain a reference to the discarded section.
9
10// UNSUPPORTED: target={{.*windows.*}}
11
12// RUN: mkdir -p %t.d
13// RUN: %clangxx_pgogen -O2 -fPIC -ffunction-sections -fdata-sections -c %s -o %t.d/a1.o -DOBJECT_1 -mllvm -disable-preinline
14// RUN: %clangxx_pgogen -O2 -fPIC -ffunction-sections -fdata-sections -c %s -o %t.d/a2.o
15// RUN: %clangxx_pgogen -fPIC -shared -o %t.d/liba.so %t.d/a1.o %t.d/a2.o 2>&1 | FileCheck %s --allow-empty
16
17// Ensure that we don't get an error when linking
18// CHECK-NOT: relocation refers to a discarded section: .text._ZN1CIiE1fEi
19
20template <typename T> struct C {21void f(T x);22int g(T x) {23f(x);24return v;25}26int v;27};28
29template <typename T>30#ifdef OBJECT_131__attribute__((weak))32#else33__attribute__((noinline))34#endif35void C<T>::f(T x) {36v += x;37}
38
39#ifdef OBJECT_140int foo() {41C<int> c;42c.f(1);43return c.g(2);44}
45#else46int bar() {47C<int> c;48c.f(3);49return c.g(4);50}
51#endif52