Skip to content

Commit 7710e0e

Browse files
committed
Revert "Reland "[pgo] Avoid introducing relocations by using private alias""
This reverts commit 3cfaea2. The runtime test fails on Mac.
1 parent 1897b67 commit 7710e0e

File tree

4 files changed

+3
-199
lines changed

4 files changed

+3
-199
lines changed

compiler-rt/test/profile/instrprof-discarded-comdat.cpp

-51
This file was deleted.

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

+3-31
Original file line numberDiff line numberDiff line change
@@ -823,36 +823,6 @@ static inline bool shouldRecordFunctionAddr(Function *F) {
823823
return F->hasAddressTaken() || F->hasLinkOnceLinkage();
824824
}
825825

826-
static inline Constant *getFuncAddrForProfData(Function *Fn) {
827-
auto *Int8PtrTy = Type::getInt8PtrTy(Fn->getContext());
828-
// Store a nullptr in __llvm_profd, if we shouldn't use a real address
829-
if (!shouldRecordFunctionAddr(Fn))
830-
return ConstantPointerNull::get(Int8PtrTy);
831-
832-
// If we can't use an alias, we must use the public symbol, even though this
833-
// may require a symbolic relocation. When the function has local linkage, we
834-
// can use the symbol directly without introducing relocations.
835-
if (Fn->isDeclarationForLinker() || Fn->hasLocalLinkage())
836-
return ConstantExpr::getBitCast(Fn, Int8PtrTy);
837-
838-
// When possible use a private alias to avoid symbolic relocations.
839-
auto *GA = GlobalAlias::create(GlobalValue::LinkageTypes::PrivateLinkage,
840-
Fn->getName(), Fn);
841-
842-
// When the instrumented function is a COMDAT function, we cannot use a
843-
// private alias. If we did, we would create reference to a local label in
844-
// this function's section. If this version of the function isn't selected by
845-
// the linker, then the metadata would introduce a reference to a discarded
846-
// section. So, for COMDAT functions, we need to adjust the linkage of the
847-
// alias. Using hidden visibility avoids a dynamic relocation and an entry in
848-
// the dynamic symbol table.
849-
if (Fn->hasComdat()) {
850-
GA->setLinkage(Fn->getLinkage());
851-
GA->setVisibility(GlobalValue::VisibilityTypes::HiddenVisibility);
852-
}
853-
return ConstantExpr::getBitCast(GA, Int8PtrTy);
854-
}
855-
856826
static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT) {
857827
// Don't do this for Darwin. compiler-rt uses linker magic.
858828
if (TT.isOSDarwin())
@@ -1044,7 +1014,9 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfInstBase *Inc) {
10441014
};
10451015
auto *DataTy = StructType::get(Ctx, makeArrayRef(DataTypes));
10461016

1047-
Constant *FunctionAddr = getFuncAddrForProfData(Fn);
1017+
Constant *FunctionAddr = shouldRecordFunctionAddr(Fn)
1018+
? ConstantExpr::getBitCast(Fn, Int8PtrTy)
1019+
: ConstantPointerNull::get(Int8PtrTy);
10481020

10491021
Constant *Int16ArrayVals[IPVK_Last + 1];
10501022
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)

llvm/test/Transforms/PGOProfile/comdat.ll

-31
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
$linkonceodr = comdat any
66
$weakodr = comdat any
7-
$weak = comdat any
8-
$linkonce = comdat any
97

108
;; profc/profd have hash suffixes. This definition doesn't have value profiling,
119
;; so definitions with the same name in other modules must have the same CFG and
@@ -29,32 +27,3 @@ define linkonce_odr void @linkonceodr() comdat {
2927
define weak_odr void @weakodr() comdat {
3028
ret void
3129
}
32-
33-
;; weak in a comdat is not renamed. There is no guarantee that definitions in
34-
;; other modules don't have value profiling. profd should be conservatively
35-
;; non-private to prevent a caller from referencing a non-prevailing profd,
36-
;; causing a linker error.
37-
; ELF: @__profc_weak = weak hidden global {{.*}} comdat, align 8
38-
; ELF: @__profd_weak = weak hidden global {{.*}} comdat($__profc_weak), align 8
39-
; COFF: @__profc_weak = weak hidden global {{.*}} comdat, align 8
40-
; COFF: @__profd_weak = weak hidden global {{.*}} comdat, align 8
41-
define weak void @weak() comdat {
42-
ret void
43-
}
44-
45-
;; profc/profd have hash suffixes. This definition doesn't have value profiling,
46-
;; so definitions with the same name in other modules must have the same CFG and
47-
;; cannot have value profiling, either. profd can be made private for ELF.
48-
; ELF: @__profc_linkonce.[[#]] = linkonce hidden global {{.*}} comdat, align 8
49-
; ELF: @__profd_linkonce.[[#]] = private global {{.*}} comdat($__profc_linkonce.[[#]]), align 8
50-
; COFF: @__profc_linkonce.[[#]] = linkonce hidden global {{.*}} comdat, align 8
51-
; COFF: @__profd_linkonce.[[#]] = linkonce hidden global {{.*}} comdat, align 8
52-
define linkonce void @linkonce() comdat {
53-
ret void
54-
}
55-
56-
; Check that comdat aliases are hidden for all linkage types
57-
; ELF: @linkonceodr.1 = linkonce_odr hidden alias void (), ptr @linkonceodr
58-
; ELF: @weakodr.2 = weak_odr hidden alias void (), ptr @weakodr
59-
; ELF: @weak.3 = weak hidden alias void (), ptr @weak
60-
; ELF: @linkonce.4 = linkonce hidden alias void (), ptr @linkonce

llvm/test/Transforms/PGOProfile/prof_avoid_relocs.ll

-86
This file was deleted.

0 commit comments

Comments
 (0)