Skip to content

Commit c555d7c

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents b2d40bb + 261a402 commit c555d7c

File tree

50 files changed

+1509
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1509
-240
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,23 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
29272927
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from data to data\n");
29282928
}
29292929

2930+
static BinaryFunction *getInitFunctionIfStaticBinary(BinaryContext &BC) {
2931+
// Workaround for https://github.com/llvm/llvm-project/issues/100096
2932+
// ("[BOLT] GOT array pointer incorrectly rewritten"). In aarch64
2933+
// static glibc binaries, the .init section's _init function pointer can
2934+
// alias with a data pointer for the end of an array. GOT rewriting
2935+
// currently can't detect this and updates the data pointer to the
2936+
// moved _init, causing a runtime crash. Skipping _init on the other
2937+
// hand should be harmless.
2938+
if (!BC.IsStaticExecutable)
2939+
return nullptr;
2940+
const BinaryData *BD = BC.getBinaryDataByName("_init");
2941+
if (!BD || BD->getSectionName() != ".init")
2942+
return nullptr;
2943+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: skip _init in for GOT workaround.\n");
2944+
return BC.getBinaryFunctionAtAddress(BD->getAddress());
2945+
}
2946+
29302947
void RewriteInstance::selectFunctionsToProcess() {
29312948
// Extend the list of functions to process or skip from a file.
29322949
auto populateFunctionNames = [](cl::opt<std::string> &FunctionNamesFile,
@@ -3047,6 +3064,9 @@ void RewriteInstance::selectFunctionsToProcess() {
30473064
return true;
30483065
};
30493066

3067+
if (BinaryFunction *Init = getInitFunctionIfStaticBinary(*BC))
3068+
Init->setIgnored();
3069+
30503070
for (auto &BFI : BC->getBinaryFunctions()) {
30513071
BinaryFunction &Function = BFI.second;
30523072

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Regression test for https://github.com/llvm/llvm-project/issues/100096
2+
# static glibc binaries crash on startup because _init is moved and
3+
# shares its address with an array end pointer. The GOT rewriting can't
4+
# tell the two pointers apart and incorrectly updates the _array_end
5+
# address. Test checks that _init is not moved.
6+
7+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
8+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static -Wl,--section-start=.data=0x1000 -Wl,--section-start=.init=0x1004
9+
# RUN: llvm-bolt %t.exe -o %t.bolt
10+
# RUN: llvm-nm %t.exe | FileCheck --check-prefix=CHECK-ORIGINAL %s
11+
# RUN: llvm-nm %t.bolt | FileCheck --check-prefix=CHECK-BOLTED %s
12+
13+
.section .data
14+
.globl _array_end
15+
_array_start:
16+
.word 0x0
17+
18+
_array_end:
19+
.section .init,"ax",@progbits
20+
.globl _init
21+
22+
# Check that bolt doesn't move _init.
23+
#
24+
# CHECK-ORIGINAL: 0000000000001004 T _init
25+
# CHECK-BOLTED: 0000000000001004 T _init
26+
_init:
27+
ret
28+
29+
.section .text,"ax",@progbits
30+
.globl _start
31+
32+
# Check that bolt is moving some other functions.
33+
#
34+
# CHECK-ORIGINAL: 0000000000001008 T _start
35+
# CHECK-BOLTED-NOT: 0000000000001008 T _start
36+
_start:
37+
bl _init
38+
adrp x0, #:got:_array_end
39+
ldr x0, [x0, #:gotpage_lo15:_array_end]
40+
adrp x0, #:got:_init
41+
ldr x0, [x0, #:gotpage_lo15:_init]
42+
ret
43+

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ createCopyFunc(mlir::Location loc, lower::AbstractConverter &converter,
744744
mlir::func::FuncOp funcOp =
745745
modBuilder.create<mlir::func::FuncOp>(loc, copyFuncName, funcType);
746746
funcOp.setVisibility(mlir::SymbolTable::Visibility::Private);
747+
fir::factory::setInternalLinkage(funcOp);
747748
builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), argsTy,
748749
{loc, loc});
749750
builder.setInsertionPointToStart(&funcOp.getRegion().back());

flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static mlir::func::FuncOp createCopyFunc(mlir::Location loc, mlir::Type varType,
153153

154154
if (auto decl = module.lookupSymbol<mlir::func::FuncOp>(copyFuncName))
155155
return decl;
156+
156157
// create function
157158
mlir::OpBuilder::InsertionGuard guard(builder);
158159
mlir::OpBuilder modBuilder(module.getBodyRegion());
@@ -161,6 +162,7 @@ static mlir::func::FuncOp createCopyFunc(mlir::Location loc, mlir::Type varType,
161162
mlir::func::FuncOp funcOp =
162163
modBuilder.create<mlir::func::FuncOp>(loc, copyFuncName, funcType);
163164
funcOp.setVisibility(mlir::SymbolTable::Visibility::Private);
165+
fir::factory::setInternalLinkage(funcOp);
164166
builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), argsTy,
165167
{loc, loc});
166168
builder.setInsertionPointToStart(&funcOp.getRegion().back());

flang/test/Integration/OpenMP/copyprivate.f90

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s
1010

11-
!CHECK-DAG: define void @_copy_box_Uxi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
12-
!CHECK-DAG: define void @_copy_10xi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
13-
!CHECK-DAG: define void @_copy_i64(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
14-
!CHECK-DAG: define void @_copy_box_Uxi64(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
15-
!CHECK-DAG: define void @_copy_f32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
16-
!CHECK-DAG: define void @_copy_2x3xf32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
17-
!CHECK-DAG: define void @_copy_z32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
18-
!CHECK-DAG: define void @_copy_10xz32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
19-
!CHECK-DAG: define void @_copy_l32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
20-
!CHECK-DAG: define void @_copy_5xl32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
21-
!CHECK-DAG: define void @_copy_c8x8(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
22-
!CHECK-DAG: define void @_copy_10xc8x8(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
23-
!CHECK-DAG: define void @_copy_c16x5(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
24-
!CHECK-DAG: define void @_copy_rec__QFtest_typesTdt(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
25-
!CHECK-DAG: define void @_copy_box_heap_Uxi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
26-
!CHECK-DAG: define void @_copy_box_ptr_Uxc8x9(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
11+
!CHECK-DAG: define internal void @_copy_box_Uxi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
12+
!CHECK-DAG: define internal void @_copy_10xi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
13+
!CHECK-DAG: define internal void @_copy_i64(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
14+
!CHECK-DAG: define internal void @_copy_box_Uxi64(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
15+
!CHECK-DAG: define internal void @_copy_f32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
16+
!CHECK-DAG: define internal void @_copy_2x3xf32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
17+
!CHECK-DAG: define internal void @_copy_z32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
18+
!CHECK-DAG: define internal void @_copy_10xz32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
19+
!CHECK-DAG: define internal void @_copy_l32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
20+
!CHECK-DAG: define internal void @_copy_5xl32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
21+
!CHECK-DAG: define internal void @_copy_c8x8(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
22+
!CHECK-DAG: define internal void @_copy_10xc8x8(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
23+
!CHECK-DAG: define internal void @_copy_c16x5(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
24+
!CHECK-DAG: define internal void @_copy_rec__QFtest_typesTdt(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
25+
!CHECK-DAG: define internal void @_copy_box_heap_Uxi32(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
26+
!CHECK-DAG: define internal void @_copy_box_ptr_Uxc8x9(ptr nocapture %{{.*}}, ptr nocapture %{{.*}})
2727

28-
!CHECK-LABEL: define void @_copy_i32(
28+
!CHECK-LABEL: define internal void @_copy_i32(
2929
!CHECK-SAME: ptr nocapture %[[DST:.*]], ptr nocapture %[[SRC:.*]]){{.*}} {
3030
!CHECK-NEXT: %[[SRC_VAL:.*]] = load i32, ptr %[[SRC]]
3131
!CHECK-NEXT: store i32 %[[SRC_VAL]], ptr %[[DST]]

flang/test/Lower/OpenMP/copyprivate.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
!CHECK-DAG: func private @_copy_box_ptr_Uxc8x9(%{{.*}}: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,9>>>>>, %{{.*}}: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.char<1,9>>>>>)
3232

3333
!CHECK-LABEL: func private @_copy_i32(
34-
!CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>) {
34+
!CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32>, %[[ARG1:.*]]: !fir.ref<i32>) attributes {llvm.linkage = #llvm.linkage<internal>} {
3535
!CHECK-NEXT: %[[DST:.*]]:2 = hlfir.declare %[[ARG0]] {uniq_name = "_copy_i32_dst"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
3636
!CHECK-NEXT: %[[SRC:.*]]:2 = hlfir.declare %[[ARG1]] {uniq_name = "_copy_i32_src"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
3737
!CHECK-NEXT: %[[SRC_VAL:.*]] = fir.load %[[SRC]]#0 : !fir.ref<i32>

flang/test/Lower/OpenMP/copyprivate2.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
!CHECK-LABEL: func private @_copy_box_ptr_i32(
55
!CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>>,
6-
!CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>>) {
6+
!CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>>)
7+
!CHECK-SAME: attributes {llvm.linkage = #llvm.linkage<internal>} {
78
!CHECK-NEXT: %[[DST:.*]]:2 = hlfir.declare %[[ARG0]] {fortran_attrs = #fir.var_attrs<pointer>,
89
!CHECK-SAME: uniq_name = "_copy_box_ptr_i32_dst"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) ->
910
!CHECK-SAME: (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
@@ -17,7 +18,8 @@
1718

1819
!CHECK-LABEL: func private @_copy_box_heap_Uxi32(
1920
!CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>,
20-
!CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) {
21+
!CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
22+
!CHECK-SAME: attributes {llvm.linkage = #llvm.linkage<internal>} {
2123
!CHECK-NEXT: %[[DST:.*]]:2 = hlfir.declare %[[ARG0]] {fortran_attrs = #fir.var_attrs<allocatable>,
2224
!CHECK-SAME: uniq_name = "_copy_box_heap_Uxi32_dst"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->
2325
!CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)

flang/test/Transforms/OpenMP/lower-workshare-alloca.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func.func @wsfunc() {
2222

2323
// CHECK-LABEL: func.func private @_workshare_copy_i32(
2424
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>,
25-
// CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32>) {
25+
// CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32>)
26+
// CHECK-SAME: attributes {llvm.linkage = #llvm.linkage<internal>} {
2627
// CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
2728
// CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref<i32>
2829
// CHECK: return

libcxx/docs/ReleaseNotes/20.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ Deprecations and Removals
105105
- The ``_LIBCPP_DISABLE_AVAILABILITY`` macro that was used to force-disable availability markup has now been removed.
106106
Whether availability markup is used by the library is now solely controlled at configuration-time.
107107

108+
- The pointer safety functions ``declare_reachable``, ``declare_no_pointers``, ``undeclare_no_pointers`` and
109+
``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
110+
way, making it very unlikely that any binary depends on them.
111+
108112
Upcoming Deprecations and Removals
109113
----------------------------------
110114

libcxx/lib/abi/CHANGELOG.TXT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ New entries should be added directly below the "Version" header.
1616
Version 20.0
1717
------------
1818

19+
* [libc++] Remove the pointer safety functions from the dylib
20+
21+
The pointer safety functions were never implemented by anyone in a non-trivial
22+
way, which lead us to removing them entirely from the headers when they were
23+
removed in C++23. This also means that just about nobody ever called these
24+
functions, especially not in production code. Because of that, we expect there
25+
to be no references in the wild to the functions in the dylib.
26+
27+
Symbol removed: _ZNSt3__117declare_reachableEPv
28+
Symbol removed: _ZNSt3__119declare_no_pointersEPcm
29+
Symbol removed: _ZNSt3__121__undeclare_reachableEPv
30+
Symbol removed: _ZNSt3__121undeclare_no_pointersEPcm
31+
1932
* [libcxx][libc] Implements from_chars floating-point
2033

2134
All platforms

0 commit comments

Comments
 (0)