[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization
dmikulin created this revision. Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, Prazek. Herald added projects: clang, Sanitizers, LLVM. Fix for https://bugs.llvm.org/show_bug.cgi?id=43390 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D67985 Files: clang/lib/CodeGen/CGExprCXX.cpp compiler-rt/test/cfi/multiple-inheritance2.cpp Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -382,7 +382,7 @@ const CXXRecordDecl *RD; std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr(*this, This.getAddress(), -MD->getParent()); +CalleeDecl->getParent()); EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc()); } Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -382,7 +382,7 @@ const CXXRecordDecl *RD; std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr(*this, This.getAddress(), -MD->getParent()); +CalleeDecl->getParent()); EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc()); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization
dmikulin updated this revision to Diff 223634. dmikulin added a comment. Added a new CodeGetCXX test case CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67985/new/ https://reviews.llvm.org/D67985 Files: clang/lib/CodeGen/CGExprCXX.cpp clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp compiler-rt/test/cfi/multiple-inheritance2.cpp Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp === --- /dev/null +++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp @@ -0,0 +1,31 @@ +// Test that correct vtable ptr and type metadata are passed to llvm.type.test +// Related to Bugzilla 43390. + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 -fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s + +class A1 { +public: +virtual int f1() = 0; +}; + +class A2 { +public: +virtual int f2() = 0; +}; + + +class B : public A1, public A2 { +public: +int f2() final { return 1; } +int f1() final { return 2; } +}; + +// CHECK-LABEL: define hidden i32 @_Z3foov +int foo() { +B b; +return static_cast(&b)->f2(); +// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8** +// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8 +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B") +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables") +} Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -382,7 +382,7 @@ const CXXRecordDecl *RD; std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr(*this, This.getAddress(), -MD->getParent()); +CalleeDecl->getParent()); EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc()); } Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp === --- /dev/null +++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp @@ -0,0 +1,31 @@ +// Test that correct vtable ptr and type metadata are passed to llvm.type.test +// Related to Bugzilla 43390. + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 -fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s + +class A1 { +public: +virtual int f1() = 0; +}; + +class A2 { +public: +virtual int f2() = 0; +}; + + +class B : public A1, public A2 { +public: +int f2() final { return 1; } +int f1() final { return 2; } +}; + +// CHECK-LABEL: define hidden i32 @_Z3foov +int foo() { +B b; +return static_cast(&b)->f2(); +// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8** +// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8 +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B") +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables") +} Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +
[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization
dmikulin added a comment. @pcc : poke CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67985/new/ https://reviews.llvm.org/D67985 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization
This revision was automatically updated to reflect the committed changes. Closed by commit rG034badb312be: CFI: wrong type passed to llvm.type.test with multiple inheritance… (authored by dmikulin). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67985/new/ https://reviews.llvm.org/D67985 Files: clang/lib/CodeGen/CGExprCXX.cpp clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp compiler-rt/test/cfi/multiple-inheritance2.cpp Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp === --- /dev/null +++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp @@ -0,0 +1,31 @@ +// Test that correct vtable ptr and type metadata are passed to llvm.type.test +// Related to Bugzilla 43390. + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 -fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s + +class A1 { +public: +virtual int f1() = 0; +}; + +class A2 { +public: +virtual int f2() = 0; +}; + + +class B : public A1, public A2 { +public: +int f2() final { return 1; } +int f1() final { return 2; } +}; + +// CHECK-LABEL: define hidden i32 @_Z3foov +int foo() { +B b; +return static_cast(&b)->f2(); +// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8** +// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8 +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B") +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables") +} Index: clang/lib/CodeGen/CGExprCXX.cpp === --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -382,7 +382,7 @@ const CXXRecordDecl *RD; std::tie(VTable, RD) = CGM.getCXXABI().LoadVTablePtr(*this, This.getAddress(), -MD->getParent()); +CalleeDecl->getParent()); EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc()); } Index: compiler-rt/test/cfi/multiple-inheritance2.cpp === --- /dev/null +++ compiler-rt/test/cfi/multiple-inheritance2.cpp @@ -0,0 +1,38 @@ +// Test that virtual functions of the derived class can be called through +// pointers of both base classes without CFI errors. +// Related to Bugzilla 43390. + +// RUN: %clangxx_cfi -o %t1 %s +// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s + +// CFI: In f1 +// CFI: In f2 +// CFI-NOT: control flow integrity check + +// REQUIRES: cxxabi + +#include + +class A1 { +public: +virtual void f1() = 0; +}; + +class A2 { +public: +virtual void f2() = 0; +}; + + +class B : public A1, public A2 { +public: +void f2() final { fprintf(stderr, "In f2\n"); } +void f1() final { fprintf(stderr, "In f1\n"); } +}; + +int main() { +B b; + +static_cast(&b)->f1(); +static_cast(&b)->f2(); +} Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp === --- /dev/null +++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp @@ -0,0 +1,31 @@ +// Test that correct vtable ptr and type metadata are passed to llvm.type.test +// Related to Bugzilla 43390. + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 -fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s + +class A1 { +public: +virtual int f1() = 0; +}; + +class A2 { +public: +virtual int f2() = 0; +}; + + +class B : public A1, public A2 { +public: +int f2() final { return 1; } +int f1() final { return 2; } +}; + +// CHECK-LABEL: define hidden i32 @_Z3foov +int foo() { +B b; +return static_cast(&b)->f2(); +// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8** +// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8 +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B") +// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables") +} Index: clang/
[PATCH] D68806: Relro is missing from the original "#pragma clang section" implementation.
This revision was automatically updated to reflect the committed changes. Closed by commit rGf14642f2f185: Added support for "#pragma clang section relro=" (authored by dmikulin). Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D68806/new/ https://reviews.llvm.org/D68806 Files: clang/docs/LanguageExtensions.rst clang/include/clang/Basic/Attr.td clang/include/clang/Basic/DiagnosticParseKinds.td clang/include/clang/Sema/Sema.h clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Parse/ParsePragma.cpp clang/lib/Sema/SemaAttr.cpp clang/lib/Sema/SemaDecl.cpp clang/test/CodeGenCXX/clang-sections.cpp clang/test/Sema/pragma-clang-section.c llvm/include/llvm/IR/GlobalVariable.h llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/Target/TargetLoweringObjectFile.cpp llvm/test/MC/ELF/section-relro.ll Index: llvm/test/MC/ELF/section-relro.ll === --- /dev/null +++ llvm/test/MC/ELF/section-relro.ll @@ -0,0 +1,65 @@ +; Tests that data and relro are correctly placed in sections +; specified by "#pragma clang section" +; RUN: llc -filetype=obj -mtriple x86_64-unknown-linux %s -o - | llvm-readobj -S -t | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux" + +@funcs_relro = hidden constant [2 x i32 ()*] [i32 ()* bitcast (i32 (...)* @func1 to i32 ()*), i32 ()* bitcast (i32 (...)* @func2 to i32 ()*)], align 16 #0 +@var_data = hidden global i32 33, align 4 #0 + +declare i32 @func1(...) +declare i32 @func2(...) + +; Function Attrs: noinline nounwind optnone sspstrong uwtable +define hidden i32 @foo(i32 %i) { +entry: + %i.addr = alloca i32, align 4 + store i32 %i, i32* %i.addr, align 4 + %0 = load i32, i32* %i.addr, align 4 + %idxprom = sext i32 %0 to i64 + %arrayidx = getelementptr inbounds [2 x i32 ()*], [2 x i32 ()*]* @funcs_relro, i64 0, i64 %idxprom + %1 = load i32 ()*, i32 ()** %arrayidx, align 8 + %call = call i32 %1() + %2 = load i32, i32* @var_data, align 4 + %add = add nsw i32 %call, %2 + ret i32 %add +} + +attributes #0 = { "data-section"=".my_data" "relro-section"=".my_relro" "rodata-section"=".my_rodata" } + +; CHECK: Section { +; CHECK:Index: +; CHECK:Name: .my_rodata +; CHECK:Type: SHT_PROGBITS (0x1) +; CHECK:Flags [ (0x2) +; CHECK: SHF_ALLOC (0x2) +; CHECK:] +; CHECK:Size: 16 +; CHECK: } +; CHECK: Section { +; CHECK:Index: +; CHECK:Name: .my_data +; CHECK:Type: SHT_PROGBITS (0x1) +; CHECK:Flags [ (0x3) +; CHECK: SHF_ALLOC (0x2) +; CHECK: SHF_WRITE (0x1) +; CHECK:] +; CHECK:Size: 4 +; CHECK: } +; CHECK: Symbol { +; CHECK:Name: funcs_relro +; CHECK:Value: 0x0 +; CHECK:Size: 16 +; CHECK:Binding: Global (0x1) +; CHECK:Type: Object (0x1) +; CHECK:Section: .my_rodata +; CHECK: } +; CHECK: Symbol { +; CHECK:Name: var_data +; CHECK:Value: 0x0 +; CHECK:Size: 4 +; CHECK:Binding: Global (0x1) +; CHECK:Type: Object (0x1) +; CHECK:Section: .my_data +; CHECK: } Index: llvm/lib/Target/TargetLoweringObjectFile.cpp === --- llvm/lib/Target/TargetLoweringObjectFile.cpp +++ llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -253,6 +253,7 @@ auto Attrs = GVar->getAttributes(); if ((Attrs.hasAttribute("bss-section") && Kind.isBSS()) || (Attrs.hasAttribute("data-section") && Kind.isData()) || +(Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) || (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly())) { return getExplicitSectionGlobal(GO, Kind, TM); } Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp === --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -568,6 +568,8 @@ SectionName = Attrs.getAttribute("bss-section").getValueAsString(); } else if (Attrs.hasAttribute("rodata-section") && Kind.isReadOnly()) { SectionName = Attrs.getAttribute("rodata-section").getValueAsString(); +} else if (Attrs.hasAttribute("relro-section") && Kind.isReadOnlyWithRel()) { + SectionName = Attrs.getAttribute("relro-section").getValueAsString(); } else if (Attrs.hasAttribute("data-section") && Kind.isData()) { SectionName = Attrs.getAttribute("data-section").getValueAsString(); } Index: llvm/include/llvm/IR/GlobalVariable.h === --- llvm/include/llvm/IR/GlobalVariable.h +++ llvm/include/llvm/IR/GlobalVariable.h @@ -243,6 +243,7 @@ bool hasImplicitSection() const { return getAttributes().hasAttribute("bss-section") ||
[PATCH] D68808: Tag CFI-generated data structures with "#pragma clang section" attributes.
This revision was automatically updated to reflect the committed changes. Closed by commit rGe2692b3bc032: Tag CFI-generated data structures with "#pragma clang section" attributes. (authored by dmikulin). Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D68808/new/ https://reviews.llvm.org/D68808 Files: clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h clang/lib/Sema/SemaDecl.cpp clang/test/CodeGen/cfi-pragma-section.c Index: clang/test/CodeGen/cfi-pragma-section.c === --- /dev/null +++ clang/test/CodeGen/cfi-pragma-section.c @@ -0,0 +1,32 @@ +// Check that CFI-generated data structures are tagged with +// "#pragma clang section" attributes + +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall \ +// RUN: -fno-sanitize-trap=cfi-icall -emit-llvm -o - %s | FileCheck %s + +// CHECK-DAG: attributes [[ATTR:#[0-9]+]]{{.*}}bss-section{{.*}}data-section{{.*}}rodata-section +// CHECK-DAG: @.src = private unnamed_addr constant{{.*}}cfi-pragma-section.c{{.*}}[[ATTR]] +// CHECK-DAG: @{{[0-9]+}} = private unnamed_addr constant{{.*}}int (int){{.*}}[[ATTR]] +// CHECK-DAG: @{{[0-9]+}} = private unnamed_addr global{{.*}}@.src{{.*}}[[ATTR]] + +typedef int (*int_arg_fn)(int); + +static int int_arg1(int arg) { +return 0; +} + +static int int_arg2(int arg) { +return 1; +} + +int_arg_fn int_funcs[2] = {int_arg1, int_arg2}; + +#pragma clang section bss = ".bss.mycfi" +#pragma clang section data = ".data.mycfi" +#pragma clang section rodata = ".rodata.mycfi" + +int main(int argc, const char *argv[]) { + +int idx = argv[1][0] - '0'; +return int_funcs[argc](idx); +} Index: clang/lib/Sema/SemaDecl.cpp === --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -9062,6 +9062,25 @@ Context, PragmaClangTextSection.SectionName, PragmaClangTextSection.PragmaLocation, AttributeCommonInfo::AS_Pragma)); + if (D.isFunctionDefinition()) { +if (PragmaClangBSSSection.Valid) + NewFD->addAttr(PragmaClangBSSSectionAttr::CreateImplicit( + Context, PragmaClangBSSSection.SectionName, + PragmaClangBSSSection.PragmaLocation)); +if (PragmaClangDataSection.Valid) + NewFD->addAttr(PragmaClangDataSectionAttr::CreateImplicit( + Context, PragmaClangDataSection.SectionName, + PragmaClangDataSection.PragmaLocation)); +if (PragmaClangRodataSection.Valid) + NewFD->addAttr(PragmaClangRodataSectionAttr::CreateImplicit( + Context, PragmaClangRodataSection.SectionName, + PragmaClangRodataSection.PragmaLocation)); +if (PragmaClangRelroSection.Valid) + NewFD->addAttr(PragmaClangRelroSectionAttr::CreateImplicit( + Context, PragmaClangRelroSection.SectionName, + PragmaClangRelroSection.PragmaLocation)); + } + // Apply an implicit SectionAttr if #pragma code_seg is active. if (CodeSegStack.CurrentValue && D.isFunctionDefinition() && !NewFD->hasAttr()) { Index: clang/lib/CodeGen/CodeGenModule.h === --- clang/lib/CodeGen/CodeGenModule.h +++ clang/lib/CodeGen/CodeGenModule.h @@ -1347,6 +1347,11 @@ /// \param QT is the clang QualType of the null pointer. llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT); + /// Set section attributes requested by "#pragma clang section" + /// \param D is the declaration to read semantic attributes from. + /// \param GO is the global object to set section attributes. + void setPragmaSectionAttributes(const Decl *D, llvm::GlobalObject *GO); + private: llvm::Constant *GetOrCreateLLVMFunction( StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable, Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1699,11 +1699,8 @@ return AddedAttr; } -void CodeGenModule::setNonAliasAttributes(GlobalDecl GD, - llvm::GlobalObject *GO) { - const Decl *D = GD.getDecl(); - SetCommonAttributes(GD, GO); - +void CodeGenModule::setPragmaSectionAttributes(const Decl *D, + llvm::GlobalObject *GO) { if (D) { if (auto *GV = dyn_cast(GO)) { if (auto *SA = D->getAttr()) @@ -1721,6 +1718,26 @@ if (!D->getAttr()) F->addFnAttr("implicit-section-name", SA->getName()); + if (auto *SA = D->getAttr()) +F->addFnAttr("bss-section", SA->getName()); + if (auto *SA = D->getAttr()) +F->addFnAttr("data-section", SA->getName()); + if (auto *SA = D->getAttr()) +F->addFnAttr("rodata-section", SA->getName()); +
[PATCH] D75274: Fix profiling option on PS4 target
This revision was automatically updated to reflect the committed changes. Closed by commit rGfbb23c9714f2: Fix profiling options on PS4 target: - libclang_rt.profile should be added when… (authored by dmikulin). Herald added a project: clang. Herald added a subscriber: cfe-commits. Changed prior to commit: https://reviews.llvm.org/D75274?vs=247032&id=250660#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75274/new/ https://reviews.llvm.org/D75274 Files: clang/lib/Driver/ToolChains/PS4CPU.cpp clang/test/Driver/ps4-runtime-flags.c Index: clang/test/Driver/ps4-runtime-flags.c === --- clang/test/Driver/ps4-runtime-flags.c +++ clang/test/Driver/ps4-runtime-flags.c @@ -10,10 +10,15 @@ // RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate=somefile.profraw %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fcs-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fcs-profile-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s // // CHECK-PS4-PROFILE: "--dependent-lib=libclang_rt.profile-x86_64.a" // CHECK-PS4-NO-PROFILE-NOT: "--dependent-lib=libclang_rt.profile-x86_64.a" Index: clang/lib/Driver/ToolChains/PS4CPU.cpp === --- clang/lib/Driver/ToolChains/PS4CPU.cpp +++ clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -30,13 +30,17 @@ if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, false) || Args.hasFlag(options::OPT_fprofile_generate, -options::OPT_fno_profile_instr_generate, false) || +options::OPT_fno_profile_generate, false) || Args.hasFlag(options::OPT_fprofile_generate_EQ, -options::OPT_fno_profile_instr_generate, false) || +options::OPT_fno_profile_generate, false) || Args.hasFlag(options::OPT_fprofile_instr_generate, options::OPT_fno_profile_instr_generate, false) || Args.hasFlag(options::OPT_fprofile_instr_generate_EQ, options::OPT_fno_profile_instr_generate, false) || + Args.hasFlag(options::OPT_fcs_profile_generate, +options::OPT_fno_profile_generate, false) || + Args.hasFlag(options::OPT_fcs_profile_generate_EQ, +options::OPT_fno_profile_generate, false) || Args.hasArg(options::OPT_fcreate_profile) || Args.hasArg(options::OPT_coverage))) CmdArgs.push_back("--dependent-lib=libclang_rt.profile-x86_64.a"); Index: clang/test/Driver/ps4-runtime-flags.c === --- clang/test/Driver/ps4-runtime-flags.c +++ clang/test/Driver/ps4-runtime-flags.c @@ -10,10 +10,15 @@ // RUN: %clang -target x86_64-scei-ps4 -fprofile-arcs -fno-profile-arcs %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s +// RUN: %clang -target x86_64-scei-ps4 -fprofile-generate -fno-profile-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-NO-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-generate=dir %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROFILE %s // RUN: %clang -target x86_64-scei-ps4 -fprofile-instr-generate %s -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-PROF