File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -449,7 +449,24 @@ static bool shouldAssumeDSOLocal(const CIRGenModule &CGM,
449
449
return false ;
450
450
451
451
if (CGOpts.DirectAccessExternalData ) {
452
- llvm_unreachable (" -fdirect-access-external-data not supported" );
452
+ // If -fdirect-access-external-data (default for -fno-pic), set dso_local
453
+ // for non-thread-local variables. If the symbol is not defined in the
454
+ // executable, a copy relocation will be needed at link time. dso_local is
455
+ // excluded for thread-local variables because they generally don't support
456
+ // copy relocations.
457
+ if (auto gv = dyn_cast<mlir::cir::GlobalOp>(GV.getOperation ()))
458
+ if (!gv.getTlsModelAttr ())
459
+ return true ;
460
+
461
+ // -fno-pic sets dso_local on a function declaration to allow direct
462
+ // accesses when taking its address (similar to a data symbol). If the
463
+ // function is not defined in the executable, a canonical PLT entry will be
464
+ // needed at link time. -fno-direct-access-external-data can avoid the
465
+ // canonical PLT entry. We don't generalize this condition to -fpie/-fpic as
466
+ // it could just cause trouble without providing perceptible benefits.
467
+ if (isa<mlir::cir::FuncOp>(GV) && !CGOpts.NoPLT &&
468
+ RM == llvm::Reloc::Static)
469
+ return true ;
453
470
}
454
471
455
472
// If we can use copy relocations we can assume it is local.
Original file line number Diff line number Diff line change
1
+ // RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-PIE -S -Xclang -emit-cir %s -o %t1.cir
2
+ // RUN: FileCheck --input-file=%t1.cir %s -check-prefix=CIR
3
+ // RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-PIE -S -Xclang -emit-llvm %s -o %t1.ll
4
+ // RUN: FileCheck --input-file=%t1.ll %s -check-prefix=LLVM
5
+
6
+ extern int var ;
7
+ int get () {
8
+ return var ;
9
+ }
10
+ // CIR: cir.global "private" external dsolocal @var : !s32i {alignment = 4 : i64}
11
+ // LLVM: @var = external dso_local global i32
You can’t perform that action at this time.
0 commit comments