[LLVMbugs] [Bug 20243] New: [X86] Call to __tls_get_addr makes the function non-leaf after it was determined to be a leaf
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Jul 8 04:16:16 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20243
Bug ID: 20243
Summary: [X86] Call to __tls_get_addr makes the function
non-leaf after it was determined to be a leaf
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: dario.domizioli at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 12754
--> http://llvm.org/bugs/attachment.cgi?id=12754&action=edit
Test case source code (see description for command lines)
Consider a simple example which accesses the address of a thread-local
variable:
// ===== ===== tls_non_leaf.cpp ===== =====
struct SomeStruct {
int x;
};
static thread_local SomeStruct ts = {0};
SomeStruct* foo(SomeStruct *t) {
return (t == 0) ? &ts : t;
}
// ===== ===== tls_non_leaf.cpp ===== =====
In PIC mode on X86, the access to &ts is lowered to a call to __tls_get_addr.
However, the lowering of such access to such call is performed under
X86AsmPrinter::EmitInstruction (which calls lowerTlsAddr), well after the
function was analysed to determine whether it contained any function calls
(i.e. whether it was a leaf or not).
This can have issues with features like -momit-leaf-frame-pointer, because the
function is not actually a leaf but it was incorrectly considered a leaf.
To reproduce, compile the source to assembly this way:
clang -O2 -fpic -fno-omit-frame-pointer -momit-leaf-frame-pointer -S -std=c++11
-o omit.s tls_non_leaf.cpp
And then this way:
clang -O2 -fpic -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -S
-std=c++11 -o no-omit.s tls_non_leaf.cpp
In theory, since the function is not really a leaf, the different options for
the leaf frame pointer should not make a difference. However, there is a
difference in the generated code because the function is mistakenly recognized
as a leaf.
My opinion is that the expansion to __tls_get_addr happens too late, it should
happen at instruction selection stage rather than in the AsmPrinter.
I have tested this on x86_64-unknown-linux with trunk at revision 212522.
However I believe this problem affects all x86_64 triples that support TLS.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140708/fd3f1903/attachment.html>
More information about the llvm-bugs
mailing list