http://bugs.gentoo.org/show_bug.cgi?id=254355 We are using patched gcc but it fail on gentoo's default compiler's to. It works fine with GCC 4.2.4 and lower. The fail file is part of libnet the symbol that miss the @PLT is libnet_getgre_length it sould have @PLT as the rest of the symbols If i compile the fail file with -pic instead i compiles fine. and have @PLT added gcc version 4.3.3 Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.3.3-r1/work/gcc-4.3.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.3.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.3.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --disable-libgcj --enable-languages=c,c++,treelang --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu Thread model: posix glibc-2.8_p20080602-r1 Intel-R-_Xeon-R-_CPU_E5420_@_2.50GHz binutils: 2.18 it add relro as default The file is compile with CFLAGS -fPIE and LDFLAGS -pie -z now
Created attachment 17205 [details] gre compile with gcc 4.3 and -fPIE -save-temps gre.i The .i file of gre thats compile with gcc 4.3.2 and CFLAGS -fPIE LDFLAGS -pie
[hjl@gnu-6 gcc]$ cat /tmp/i.i inline void foo (); void bar () { foo (); } [hjl@gnu-6 gcc]$ ./xgcc -B./ -S /tmp/i.i -m32 -fPIC [hjl@gnu-6 gcc]$ cat i.s .file "i.i" .text .globl bar .type bar, @function bar: pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp call __i686.get_pc_thunk.bx addl $_GLOBAL_OFFSET_TABLE_, %ebx call foo@PLT addl $4, %esp popl %ebx popl %ebp ret .size bar, .-bar
[hjl@gnu-6 gcc]$ ./xgcc -B./ -fpie -S /tmp/i.i -m32 -fpie [hjl@gnu-6 gcc]$ cat i.s .file "i.i" .text .globl bar .type bar, @function bar: pushl %ebp movl %esp, %ebp subl $8, %esp call foo leave ret .size bar, .-bar
I don't see the issue with using the non PLT with -fPIE.
Why do you think this is a bug? PowerPC32-linux-gnu produces: bl foo@local
Since default_binds_local_p_1 returns true as shlib is false for -fPIE, I still don't see any issues here except for the fact the linker not doing the correct thing.
Linker does complain: [hjl@gnu-6 gcc]$ cat /tmp/i.i inline void foo (); int main () { foo (); return 0; } [hjl@gnu-6 gcc]$ gcc /tmp/i.i -fpie -pie /tmp/ccOgMGls.o: In function `main': i.i:(.text+0xa): undefined reference to `foo' /usr/local/bin/ld: /tmp/ccOgMGls.o: relocation R_X86_64_PC32 against undefined symbol `foo' can not be used when making a shared object; recompile with -fPIC /usr/local/bin/ld: final link failed: Bad value collect2: ld returned 1 exit status [hjl@gnu-6 gcc]$
This patch: --- Index: varasm.c =================================================================== --- varasm.c (revision 5094) +++ varasm.c (working copy) @@ -6321,6 +6321,11 @@ default_binds_local_p_1 (const_tree exp, && (DECL_INITIAL (exp) == NULL || DECL_INITIAL (exp) == error_mark_node)) local_p = false; + /* Functions marked inline without body are not local. */ + else if (TREE_CODE (exp) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (exp) + && DECL_INITIAL (exp) == NULL) + local_p = false; /* Otherwise we're left with initialized (or non-common) global data which is of necessity defined locally. */ else --- works for me
A patch is posted at http://gcc.gnu.org/ml/gcc-patches/2009-01/msg01423.html
No compiler with -fpie support manages to do this "correct". Not a regression. IMHO this is invalid. 6.7.4/6 "... If a function is declared with an inline function specifier, then it shall also be defined in the same translation unit." which is obviously not the case here. That is C99 of course, so you might argue that for GNU C89 the situation should be different, but then the frontend should properly mark the declaration extern.
I don't get the link error with gcc 4.2.4 on the code in comment #7
My testcase is > cat t2.c void foo() {} > cat t.c inline void foo (); int main () { foo (); return 0; } which works perfectly fine even with 4.3 and 4.4 if I build both t2.c and t.c with -fpie and fails with all compilers supporting -fpie if I only build t.c with -fpie but t2.c not. They bind locally with 4.3 and 4.4 though.
(In reply to comment #12) > My testcase is > > > cat t2.c > void foo() {} The problem happens when t2.c is in a shared library. > > cat t.c > inline void foo (); > int main () > { > foo (); > return 0; > } > > which works perfectly fine even with 4.3 and 4.4 if I build both t2.c and t.c > with -fpie and fails with all compilers supporting -fpie if I only build > t.c with -fpie but t2.c not. > We can argue that this code is invalid and gcc shouldn't accept it in the first place. But from user perspective, gcc 4.3 doesn't work on their codes any more silently.
Created attachment 17211 [details] A patch This patch only checks --- gcc/varasm.c.pie 2008-11-30 08:49:54.000000000 -0800 +++ gcc/varasm.c 2009-01-29 07:50:46.000000000 -0800 @@ -6321,6 +6321,10 @@ default_binds_local_p_1 (const_tree exp, && (DECL_INITIAL (exp) == NULL || DECL_INITIAL (exp) == error_mark_node)) local_p = false; + /* Functions without body are not local. */ + else if (TREE_CODE (exp) == FUNCTION_DECL + && DECL_INITIAL (exp) == NULL) + local_p = false; /* Otherwise we're left with initialized (or non-common) global data which is of necessity defined locally. */ else
We have this in the shared library that is compile with -fPIC inline u_int32_t libnet_getgre_length(u_int16_t fv) { code } And the app have code len = libnet_getgre_length(gre_flags); size += len; code
Patch to set DECL_EXTERNAL instead: http://gcc.gnu.org/ml/gcc-patches/2009-01/msg01525.html
Subject: Bug 39013 Author: jakub Date: Fri Jan 30 20:46:32 2009 New Revision: 143803 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143803 Log: PR target/39013 * c-decl.c (pop_scope): Set DECL_EXTERNAL for functions declared inline but never defined. * gcc.target/i386/pr39013-1.c: New test. * gcc.target/i386/pr39013-2.c: New test. Added: trunk/gcc/testsuite/gcc.target/i386/pr39013-1.c trunk/gcc/testsuite/gcc.target/i386/pr39013-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-decl.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk so far.
Created attachment 17218 [details] fixed for gcc 4.3.3 Thanx for the help The patch fix the error i have.
Created attachment 17565 [details] Got ICE when compile some code with the old patch. See http://bugs.gentoo.org/show_bug.cgi?id=262567 for ICE when compiling.
Testing a backport.
Subject: Bug 39013 Author: rguenth Date: Fri Jun 19 12:23:16 2009 New Revision: 148700 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148700 Log: 2009-06-19 Richard Guenther <rguenther@suse.de> Backport from mainline: 2009-04-22 Jakub Jelinek <jakub@redhat.com> PR c/39855 * fold-const.c (fold_binary) <case LSHIFT_EXPR>: When optimizing into 0, use omit_one_operand. * gcc.dg/torture/pr39855.c: New test. 2009-01-30 Jakub Jelinek <jakub@redhat.com> PR target/39013 * c-decl.c (pop_scope): Set DECL_EXTERNAL for functions declared inline but never defined. * gcc.target/i386/pr39013-1.c: New test. * gcc.target/i386/pr39013-2.c: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/torture/pr39855.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/pr39013-1.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/pr39013-2.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/c-decl.c branches/gcc-4_3-branch/gcc/fold-const.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed.