Skip to content

Commit 52307f8

Browse files
committed
[CHERIoT] Generate export table entries for weak function symbols.
These arise in newer libc++'s, where a library is used for explicit instantiations of some std::string methods. These become weakly exported libcall symbols from the library, and still need to be present in the export table. Since they should only ever be materialized in one translation unit, it's OK for the export table entry to be strongly exported while the symbol itself is weakly exported.
1 parent b136f35 commit 52307f8

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,10 @@ void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
742742
/*IsImport*/ false);
743743
auto Sym = C.getOrCreateSymbol(ExportName);
744744
OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
745-
// If the function isn't global, don't make its export table entry
746-
// global either. Two different compilation units in the same
747-
// compartment may export different static things.
748-
if (Entry.Fn.hasExternalLinkage() && !Entry.forceLocal)
745+
// If the function isn't global, don't make its export table entry global
746+
// either. Two different compilation units in the same compartment may
747+
// export different static things.
748+
if (!Entry.Fn.isDiscardableIfUnused() && !Entry.forceLocal)
749749
OutStreamer->emitSymbolAttribute(Sym, MCSA_Global);
750750
OutStreamer->emitValueToAlignment(Align(4));
751751
OutStreamer->emitLabel(Sym);
@@ -771,7 +771,7 @@ void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
771771
// Emit symbol alias in the export table for the alias using the same
772772
// attributes, linkage, and size as the primary entry.
773773
OutStreamer->emitSymbolAttribute(AliasExportSym, MCSA_ELF_TypeObject);
774-
if (GA->hasExternalLinkage() && !Entry.forceLocal)
774+
if (!GA->isDiscardableIfUnused() && !Entry.forceLocal)
775775
OutStreamer->emitSymbolAttribute(AliasExportSym, MCSA_Global);
776776
OutStreamer->emitAssignment(AliasExportSym,
777777
MCSymbolRefExpr::create(Sym, C));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc --filetype=asm --mcpu=cheriot --mtriple=riscv32cheriot-unknown-cheriotrtos -target-abi cheriot %s -mattr=+xcheri,+cap-mode,+xcheriot -o - | FileCheck %s
2+
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128-pf200:64:64:64:32-A200-P200-G200"
3+
target triple = "riscv32cheriot-unknown-cheriotrtos"
4+
5+
; Verify that we emit an export table entry for a weak function
6+
7+
; CHECK: .section .compartment_exports,"aR",@progbits
8+
; CHECK .type __library_export_libcalls_foo,@object
9+
; CHECK: .p2align 2, 0x0
10+
; CHECK: __library_export_libcalls_foo:
11+
; CHECK: .half foo-__compartment_pcc_start
12+
; CHECK: .byte 0
13+
; CHECK: .byte 0
14+
; CHECK: .size __library_export_libcalls_foo, 4
15+
16+
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
17+
define weak dso_local cherilibcallcc noundef i32 @foo() local_unnamed_addr addrspace(200) #0 {
18+
entry:
19+
ret i32 42
20+
}
21+
22+
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cheriot" "target-features"="+32bit,+c,+cap-mode,+e,+m,+relax,+xcheri,+zmmul,-a,-b,-d,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-f,-h,-i,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-v,-xcheriot,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zacas,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b" }
23+
24+
!llvm.module.flags = !{!0, !1, !2, !4}
25+
!llvm.ident = !{!5}
26+
27+
!0 = !{i32 1, !"wchar_size", i32 4}
28+
!1 = !{i32 1, !"target-abi", !"cheriot"}
29+
!2 = !{i32 6, !"riscv-isa", !3}
30+
!3 = !{!"rv32e2p0_m2p0_c2p0_zmmul1p0_xcheri0p0"}
31+
!4 = !{i32 8, !"SmallDataLimit", i32 0}
32+
!5 = !{!"clang version 20.1.3 ([email protected]:resistor/llvm-project-1.git b5150572190bf7926bc7c77858e6f6d49f49b0bb)"}

0 commit comments

Comments
 (0)