Skip to content

Commit 739e6d5

Browse files
Add warning about libpulp TLS support
TLS variables in libpulp needs to call __tls_get_addr manually, which certainly would require quite lot of code to properly support it in the SymbolExternalizer. Therefore, add a warn message about the necessity of human intervention for that. Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
1 parent 7ad9595 commit 739e6d5

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

libcextract/DscFileGenerator.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ void DscFileGenerator::Global_Functions(void)
9292
}
9393
}
9494

95-
static bool Is_TLS(VarDecl *decl)
96-
{
97-
return decl->getTLSKind() == VarDecl::TLS_None ? false : true;
98-
}
99-
10095
static bool Is_TLS(const DeclContext::lookup_result &decls)
10196
{
10297
bool is_tls = false;

libcextract/LLVMMisc.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,10 @@ bool Is_Decl_Equivalent_To(Decl *a, Decl *b);
112112

113113
/** Check if string has unmatched #if, #ifdef, #ifndef. */
114114
bool Has_Balanced_Ifdef(const StringRef &string);
115+
116+
117+
/** Check if the VarDecl is declared as TLS. */
118+
static inline bool Is_TLS(VarDecl *decl)
119+
{
120+
return decl->getTLSKind() == VarDecl::TLS_None ? false : true;
121+
}

libcextract/SymbolExternalizer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,18 @@ VarDecl *SymbolExternalizer::Create_Externalized_Var(DeclaratorDecl *decl, const
650650
variable as well. */
651651
if (VarDecl *vdecl = dyn_cast<VarDecl>(decl)) {
652652
ret->setTSCSpec(vdecl->getTSCSpec());
653+
654+
/* Libpulp support TLS through some ugly hacking. Warn the user about it
655+
for now. */
656+
if (Is_TLS(vdecl)) {
657+
std::string msg = "Externalization of TLS variable " +
658+
vdecl->getName().str() +
659+
" requires human intervention to call __tls_get_addr";
660+
661+
662+
DiagsClass::Emit_Warn(msg, vdecl->getSourceRange(),
663+
AST->getSourceManager());
664+
}
653665
}
654666

655667
/* return node. */

testsuite/small/tls-2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=set_errno -DCE_EXPORT_SYMBOLS=__libc_errno" }*/
2+
/* { dg-xfail }*/
3+
4+
extern __thread int __libc_errno __attribute__ ((tls_model ("initial-exec")));
5+
6+
void set_errno(int err)
7+
{
8+
__libc_errno = err;
9+
}
10+
11+
/* { dg-final { scan-tree-dump "__attribute__\(\(used\)\) static tls_index klpe___libc_errno_ti;" } } */
12+
/* { dg-final { scan-tree-dump "__tls_get_addr\(klpe___libc_errno_ti\)" } } */

0 commit comments

Comments
 (0)