[cfe-commits] r160174 - in /cfe/trunk: lib/AST/Decl.cpp test/CodeGenCXX/visibility-inlines-hidden.cpp
Tobias Grosser
tobias at grosser.es
Sat Sep 29 14:42:52 PDT 2012
On 09/23/2012 07:51 PM, Tobias Grosser wrote:
> On 07/13/2012 04:25 PM, Rafael Espindola wrote:
>> Author: rafael
>> Date: Fri Jul 13 09:25:36 2012
>> New Revision: 160174
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=160174&view=rev
>> Log:
>> Use -fvisibility-inlines-hidden in inline functions too. This matches gcc
>> behavior since gcc pr30066. Thanks to Benjamin Kramer for pointing it
>> out.
>
> This commit causes clang to fail, when compiling Polly.
>
> The error I get is:
>
> /usr/bin/ld: error:
> tools/polly/lib/Analysis/CMakeFiles/PollyAnalysis.dir/ScopInfo.cpp.o:
> requires dynamic R_X86_64_PC32 reloc against '__gmpz_neg' which may
> overflow at runtime; recompile with -fPIC
>
> I get the same error on other projects that use
> -fvisibility-inlines-hidden in combination with gmp. The error
> disappears with older versions of gcc and clang. There is also no error
> if I use gcc 4.7, even though gcc 4.7 should have the functionality that
> was introduced in this commit (pr30066 is part of gcc4.7).
>
> I looked into this and reduced a test case:
>
> extern __inline__ __attribute__ ((__gnu_inline__))
> void foo() {}
>
> void bar() {
> foo();
> }
>
> I compiled with both current clang++ and g++-4.7.
>
> g++-4.7 -S test-visiblity-inlines-hidden-gnuinline.cpp
> -fvisibility-inlines-hidden -O0 -o g++.s
>
> clang++ -S test-visiblity-inlines-hidden-gnuinline.cpp
> -fvisibility-inlines-hidden -O0 -o clang.s
>
> Both, clang.s and g++.s, contain no implementation of foo, but a call to
> foo. However, clang.s contains the string ".hidden _Z3foov", g++.s does
> not contain the string. This difference seems to cause incorrect
> relocation information.
>
> The attached patch fixes this for me. I also tried to add a test case,
> but was not sure what LLVM-IR output I should put into the CHECK-line.
> Can anybody comment on the solution?
Rafael, could you have a look?
Tobi
-------------- next part --------------
>From a5890a4e2aa5b35c7aff792ffd1004f3f9afeeef Mon Sep 17 00:00:00 2001
From: Tobias Grosser <tobias at grosser.es>
Date: Sun, 23 Sep 2012 19:39:40 +0200
Subject: [PATCH] Fix InlineVisibilityHidden with GNUInlineAttr
---
clang/lib/AST/Decl.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 13f931a..2eca7cc 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -193,7 +193,8 @@ static bool useInlineVisibilityHidden(const NamedDecl *D) {
// anyway.
return TSK != TSK_ExplicitInstantiationDeclaration &&
TSK != TSK_ExplicitInstantiationDefinition &&
- FD->hasBody(Def) && Def->isInlined();
+ FD->getASTContext().getLangOpts().InlineVisibilityHidden &&
+ FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr<GNUInlineAttr>();
}
static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
--
1.7.9.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-visiblity-inlines-hidden-gnuinline.cpp
Type: text/x-c++src
Size: 89 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120929/fe540430/attachment.cpp>
-------------- next part --------------
.file "test-visiblity-inlines-hidden-gnuinline.cpp"
.text
.globl _Z3barv
.align 16, 0x90
.type _Z3barv, at function
_Z3barv: # @_Z3barv
.cfi_startproc
# BB#0: # %entry
pushq %rbp
.Ltmp2:
.cfi_def_cfa_offset 16
.Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Ltmp4:
.cfi_def_cfa_register %rbp
callq _Z3foov
popq %rbp
ret
.Ltmp5:
.size _Z3barv, .Ltmp5-_Z3barv
.cfi_endproc
.hidden _Z3foov
.section ".note.GNU-stack","", at progbits
-------------- next part --------------
.file "test-visiblity-inlines-hidden-gnuinline.cpp"
.text
.globl _Z3barv
.type _Z3barv, @function
_Z3barv:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
call _Z3foov
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size _Z3barv, .-_Z3barv
.ident "GCC: (Ubuntu/Linaro 4.7.0-7ubuntu3) 4.7.0"
.section .note.GNU-stack,"", at progbits
More information about the cfe-commits
mailing list