This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bad PIC on Solaris


On Jan 26, 2000, Alexandre Oliva <oliva@lsd.ic.unicamp.br> wrote:

> GCC won't emit PIC typeinfo nodes on Solaris, both /sparc and /x86.
> GNU ld doesn't complain when a shared library is created with an
> object file containing such typeinfo nodes, but Sun ld does, when run
> with `-z text'.  For example, given the following file:

> class foo {};
> class bar : foo {};

> #include <typeinfo>

> int main() {
>   typeid(bar);
> }

> % g++ -shared -fPIC test.cc -o /dev/null
> ld: Software Generation Utilities - Solaris/ELF (3.0)
> Text relocation remains                         referenced
>     against symbol                  offset      in file
> foo type_info node                  0x0         test.o
> ld: fatal: relocations remain against allocatable but non-writable sections
> collect2: ld returned 1 exit status

Here's a patch that fixes this problem.  Tested on Solaris2.6/sparc
and 7/x86, as well as RedHat Linux 6.2 /x86 and /alpha.  Ok to
install?

Index: gcc/ChangeLog
2000-04-10  Alexandre Oliva  <oliva@lsd.ic.unicamp.br>

	* config/elfos.h (SELECT_SECTION): Decide whether to use a data or
	const section to output a CONSTRUCTOR based on the same conditions
	used for VAR_DECLs.

Index: gcc/config/elfos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/elfos.h,v
retrieving revision 1.15
diff -u -r1.15 elfos.h
--- gcc/config/elfos.h	2000/02/26 20:03:11	1.15
+++ gcc/config/elfos.h	2000/04/10 19:52:41
@@ -484,7 +484,8 @@
       else							\
 	data_section ();					\
     }								\
-  else if (TREE_CODE (DECL) == VAR_DECL)			\
+  else if (TREE_CODE (DECL) == VAR_DECL				\
+	   || TREE_CODE (DECL) == CONSTRUCTOR)			\
     {								\
       if ((flag_pic && RELOC)					\
 	  || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL)	\

-- 
Alexandre Oliva    Enjoy Guaranį, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]