This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC/A: Add a bfd hook for defining common symbols


Nick Clifton <nickc@redhat.com> writes:
> Hi Richard,
>
>> What I'm trying to do is here is change something that ld/ does directly
>> in such a way that some internal bfd datastructures are kept up to date.
>> If we added a linker emulation hook, it would exist _purely_ for bookkeeping
>> reasons, not semantic reasons.
>
> I agree.  I also like your proposal, although I think that the new 
> define-a-common function needs a bit of work.  Specifically:
>
>    * Be paranoid - this is an API function - add some error checking of 
> the inputs.  (eg H being NULL or H->type not being bfd_link_hash_common).
>
>    * Add a boolean return value.  If the function fails to perform its 
> duties it should set bfd_error and return FALSE.
>
>    * The code in lang_one_common() took note of the setting of 
> bfd_arch_mach_octets_per_byte (via the opb_shift variable), whereas you 
> appear to have dropped this.
>
>   * A more descriptive description would be nice.  Eg something like 
> "Convert the common symbol H to a regular defined symbol.  Returns TRUE 
> upon success, FALSE otherwise."

OK, how does this look?  Tested in the same way as before.

Thanks,
Richard


bfd/
	* aout-adobe.c (aout_32_bfd_define_common_symbol): Define.
	* aout-target.h (MY_bfd_define_common_symbol): Likewise.
	* aout-tic30.c (MY_bfd_define_common_symbol): Likewise.
	* binary.c (binary_bfd_define_common_symbol): Likewise.
	* bout.c (b_out_bfd_define_common_symbol): Likewise.
	* coff-alpha.c (_bfd_ecoff_bfd_define_common_symbol): Likewise.
	* coff-mips.c (_bfd_ecoff_bfd_define_common_symbol): Likewise.
	* coffcode.h (coff_bfd_define_common_symbol): Likewise.
	* elfxx-target.h (bfd_elfNN_bfd_define_common_symbol): Likewise.
	* i386msdos.c (msdos_bfd_define_common_symbol): Likewise.
	* i386os9k.c (os9k_bfd_define_common_symbol): Likewise.
	* ieee.c (ieee_bfd_define_common_symbol): Likewise.
	* ihex.c (ihex_bfd_define_common_symbol): Likewise.
	* libbfd-in.h (_bfd_nolink_bfd_define_common_symbol): Likewise.
	* mach-o.c (bfd_mach_o_bfd_define_common_symbol): Likewise.
	* mmo.c (mmo_bfd_define_common_symbol): Likewise.
	* nlm-target.h (nlm_bfd_define_common_symbol): Likewise.
	* oasys.c (oasys_bfd_define_common_symbol): Likewise.
	* pef.c (bfd_pef_bfd_define_common_symbol): Likewise.
	* ppcboot.c (ppcboot_bfd_define_common_symbol): Likewise.
	* som.c (som_bfd_define_common_symbol): Likewise.
	* srec.c (srec_bfd_define_common_symbol): Likewise.
	* tekhex.c (tekhex_bfd_define_common_symbol): Likewise.
	* versados.c (versados_bfd_define_common_symbol): Likewise.
	* vms.c (vms_bfd_define_common_symbol): Likewise.
	* xcoff-target.h (_bfd_xcoff_bfd_define_common_symbol): Likewise.
	* xsym.c (bfd_sym_bfd_define_common_symbol): Likewise.
	* coff-rs6000.c (rs6000coff_vec): Add _bfd_xcoff_define_common_symbol.
	(pmac_xcoff_vec): Likewise.
	* coff64-rs6000.c (rs6000coff64_vec): Likewise.
	(aix5coff64_vec): Likewise.
	* linker.c (bfd_generic_define_common_symbol): New function.
	* targets.c (BFD_JUMP_TABLE_LINK): Add NAME##_bfd_define_common_symbol.
	(_bfd_define_common_symbol): New field.
	* libcoff-in.h (_bfd_xcoff_define_common_symbol): Declare.
	* xcofflink.c (_bfd_xcoff_define_common_symbol): New function.
	(xcoff_build_ldsyms): Don't set XCOFF_DEF_REGULAR for common
	symbols here.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Likewise.
	* libcoff.h: Likewise.

ld/
	* ldlang.c (lang_one_common): Use bfd_define_common_symbol.

ld/testsuite/
	* ld-powerpc/aix-export-2.s, ld-powerpc/aix-export-2.nd: New test.
	* ld-powerpc/aix52.exp: Run it.

Index: bfd/aout-adobe.c
===================================================================
--- bfd/aout-adobe.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/aout-adobe.c	2009-04-02 19:51:32.000000000 +0100
@@ -463,6 +463,7 @@ #define aout_32_bfd_merge_sections	     
 #define aout_32_bfd_is_group_section	            bfd_generic_is_group_section
 #define aout_32_bfd_discard_group	            bfd_generic_discard_group
 #define aout_32_section_already_linked              _bfd_generic_section_already_linked
+#define aout_32_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define aout_32_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
 #define aout_32_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define aout_32_bfd_link_add_symbols	            _bfd_generic_link_add_symbols
Index: bfd/aout-target.h
===================================================================
--- bfd/aout-target.h	2009-04-01 19:05:10.000000000 +0100
+++ bfd/aout-target.h	2009-04-02 19:51:32.000000000 +0100
@@ -493,6 +493,9 @@ #define MY_bfd_discard_group bfd_generic
 #define MY_section_already_linked \
   _bfd_generic_section_already_linked
 #endif
+#ifndef MY_bfd_define_common_symbol
+#define MY_bfd_define_common_symbol bfd_generic_define_common_symbol
+#endif
 #ifndef MY_bfd_reloc_type_lookup
 #define MY_bfd_reloc_type_lookup NAME (aout, reloc_type_lookup)
 #endif
Index: bfd/aout-tic30.c
===================================================================
--- bfd/aout-tic30.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/aout-tic30.c	2009-04-02 19:51:32.000000000 +0100
@@ -950,6 +950,9 @@ #define MY_bfd_discard_group bfd_generic
 #define MY_section_already_linked \
   _bfd_generic_section_already_linked
 #endif
+#ifndef MY_bfd_define_common_symbol
+#define MY_bfd_define_common_symbol bfd_generic_define_common_symbol
+#endif
 #ifndef MY_bfd_reloc_type_lookup
 #define MY_bfd_reloc_type_lookup tic30_aout_reloc_type_lookup
 #endif
Index: bfd/binary.c
===================================================================
--- bfd/binary.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/binary.c	2009-04-02 19:51:32.000000000 +0100
@@ -316,6 +316,7 @@ #define binary_bfd_merge_sections       
 #define binary_bfd_is_group_section                bfd_generic_is_group_section
 #define binary_bfd_discard_group                   bfd_generic_discard_group
 #define binary_section_already_linked             _bfd_generic_section_already_linked
+#define binary_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define binary_bfd_link_hash_table_create         _bfd_generic_link_hash_table_create
 #define binary_bfd_link_hash_table_free           _bfd_generic_link_hash_table_free
 #define binary_bfd_link_just_syms                 _bfd_generic_link_just_syms
Index: bfd/bout.c
===================================================================
--- bfd/bout.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/bout.c	2009-04-02 19:51:32.000000000 +0100
@@ -1389,6 +1389,7 @@ #define b_out_bfd_merge_sections        
 #define b_out_bfd_is_group_section             bfd_generic_is_group_section
 #define b_out_bfd_discard_group                bfd_generic_discard_group
 #define b_out_section_already_linked           _bfd_generic_section_already_linked
+#define b_out_bfd_define_common_symbol         bfd_generic_define_common_symbol
 #define aout_32_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
 
 extern const bfd_target b_out_vec_little_host;
Index: bfd/coff-alpha.c
===================================================================
--- bfd/coff-alpha.c	2009-04-01 19:05:10.000000000 +0100
+++ bfd/coff-alpha.c	2009-04-02 19:51:32.000000000 +0100
@@ -2398,6 +2398,7 @@ #define _bfd_ecoff_bfd_is_group_section 
 #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
 #define _bfd_ecoff_section_already_linked \
   _bfd_generic_section_already_linked
+#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
 
 const bfd_target ecoffalpha_little_vec =
 {
Index: bfd/coff-mips.c
===================================================================
--- bfd/coff-mips.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/coff-mips.c	2009-04-02 19:51:32.000000000 +0100
@@ -1417,6 +1417,7 @@ #define _bfd_ecoff_bfd_is_group_section 
 #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group
 #define _bfd_ecoff_section_already_linked \
   _bfd_generic_section_already_linked
+#define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol
 
 extern const bfd_target ecoff_big_vec;
 
Index: bfd/coffcode.h
===================================================================
--- bfd/coffcode.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/coffcode.h	2009-04-02 19:51:32.000000000 +0100
@@ -5591,6 +5591,10 @@ #define coff_section_already_linked \
   _bfd_generic_section_already_linked
 #endif
 
+#ifndef coff_bfd_define_common_symbol
+#define coff_bfd_define_common_symbol	    bfd_generic_define_common_symbol
+#endif
+
 #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)	\
 const bfd_target VAR =							\
 {									\
Index: bfd/elfxx-target.h
===================================================================
--- bfd/elfxx-target.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/elfxx-target.h	2009-04-02 19:51:32.000000000 +0100
@@ -169,6 +169,10 @@ #define bfd_elfNN_section_already_linked
   _bfd_elf_section_already_linked
 #endif
 
+#ifndef bfd_elfNN_bfd_define_common_symbol
+#define bfd_elfNN_bfd_define_common_symbol bfd_generic_define_common_symbol
+#endif
+
 #ifndef bfd_elfNN_bfd_make_debug_symbol
 #define bfd_elfNN_bfd_make_debug_symbol \
   ((asymbol * (*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
Index: bfd/i386msdos.c
===================================================================
--- bfd/i386msdos.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/i386msdos.c	2009-04-02 19:51:32.000000000 +0100
@@ -148,6 +148,7 @@ #define msdos_bfd_is_group_section bfd_g
 #define msdos_bfd_discard_group bfd_generic_discard_group
 #define msdos_section_already_linked \
   _bfd_generic_section_already_linked
+#define msdos_bfd_define_common_symbol bfd_generic_define_common_symbol
 #define msdos_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define msdos_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define msdos_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/i386os9k.c
===================================================================
--- bfd/i386os9k.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/i386os9k.c	2009-04-02 19:51:32.000000000 +0100
@@ -172,6 +172,7 @@ #define os9k_bfd_is_group_section bfd_ge
 #define os9k_bfd_discard_group bfd_generic_discard_group
 #define os9k_section_already_linked \
   _bfd_generic_section_already_linked
+#define os9k_bfd_define_common_symbol bfd_generic_define_common_symbol
 #define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define os9k_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/ieee.c
===================================================================
--- bfd/ieee.c	2009-04-01 19:05:10.000000000 +0100
+++ bfd/ieee.c	2009-04-02 19:51:32.000000000 +0100
@@ -3770,6 +3770,7 @@ #define ieee_bfd_is_group_section bfd_ge
 #define ieee_bfd_discard_group bfd_generic_discard_group
 #define ieee_section_already_linked \
   _bfd_generic_section_already_linked
+#define ieee_bfd_define_common_symbol bfd_generic_define_common_symbol
 #define ieee_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define ieee_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define ieee_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/ihex.c
===================================================================
--- bfd/ihex.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/ihex.c	2009-04-02 19:51:32.000000000 +0100
@@ -933,6 +933,7 @@ #define ihex_bfd_merge_sections         
 #define ihex_bfd_is_group_section                 bfd_generic_is_group_section
 #define ihex_bfd_discard_group                    bfd_generic_discard_group
 #define ihex_section_already_linked               _bfd_generic_section_already_linked
+#define ihex_bfd_define_common_symbol             bfd_generic_define_common_symbol
 #define ihex_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
 #define ihex_bfd_link_hash_table_free             _bfd_generic_link_hash_table_free
 #define ihex_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
Index: bfd/libbfd-in.h
===================================================================
--- bfd/libbfd-in.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/libbfd-in.h	2009-04-02 20:11:53.000000000 +0100
@@ -416,6 +416,9 @@ #define _bfd_nolink_bfd_link_split_secti
   ((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false)
 #define _bfd_nolink_section_already_linked \
   ((void (*) (bfd *, struct bfd_section *, struct bfd_link_info *)) bfd_void)
+#define _bfd_nolink_bfd_define_common_symbol \
+  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, \
+		     struct bfd_link_hash_entry *)) bfd_false)
 
 /* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
    have dynamic symbols or relocs.  Use BFD_JUMP_TABLE_DYNAMIC
Index: bfd/mach-o.c
===================================================================
--- bfd/mach-o.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/mach-o.c	2009-04-02 19:51:32.000000000 +0100
@@ -72,6 +72,7 @@ #define bfd_mach_o_bfd_merge_sections   
 #define bfd_mach_o_bfd_is_group_section               bfd_generic_is_group_section
 #define bfd_mach_o_bfd_discard_group                  bfd_generic_discard_group
 #define bfd_mach_o_section_already_linked             _bfd_generic_section_already_linked
+#define bfd_mach_o_bfd_define_common_symbol           bfd_generic_define_common_symbol
 #define bfd_mach_o_bfd_copy_private_header_data       _bfd_generic_bfd_copy_private_header_data
 #define bfd_mach_o_core_file_matches_executable_p     generic_core_file_matches_executable_p
 
Index: bfd/mmo.c
===================================================================
--- bfd/mmo.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/mmo.c	2009-04-02 19:51:32.000000000 +0100
@@ -3211,6 +3211,7 @@ #define mmo_bfd_is_group_section bfd_gen
 #define mmo_bfd_discard_group bfd_generic_discard_group
 #define mmo_section_already_linked \
   _bfd_generic_section_already_linked
+#define mmo_bfd_define_common_symbol bfd_generic_define_common_symbol
 
 /* We want to copy time of creation, otherwise we'd use
    BFD_JUMP_TABLE_COPY (_bfd_generic).  */
Index: bfd/nlm-target.h
===================================================================
--- bfd/nlm-target.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/nlm-target.h	2009-04-02 19:51:32.000000000 +0100
@@ -49,6 +49,7 @@ #define nlm_bfd_merge_sections          
 #define nlm_bfd_is_group_section                bfd_generic_is_group_section
 #define nlm_bfd_discard_group                   bfd_generic_discard_group
 #define nlm_section_already_linked              _bfd_generic_section_already_linked
+#define nlm_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define nlm_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
 #define nlm_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define nlm_bfd_link_add_symbols                _bfd_generic_link_add_symbols
Index: bfd/oasys.c
===================================================================
--- bfd/oasys.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/oasys.c	2009-04-02 19:51:32.000000000 +0100
@@ -1198,6 +1198,7 @@ #define oasys_bfd_merge_sections        
 #define oasys_bfd_is_group_section                 bfd_generic_is_group_section
 #define oasys_bfd_discard_group                    bfd_generic_discard_group
 #define oasys_section_already_linked               _bfd_generic_section_already_linked
+#define oasys_bfd_define_common_symbol             bfd_generic_define_common_symbol
 #define oasys_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
 #define oasys_bfd_link_hash_table_free             _bfd_generic_link_hash_table_free
 #define oasys_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
Index: bfd/pef.c
===================================================================
--- bfd/pef.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/pef.c	2009-04-02 19:51:32.000000000 +0100
@@ -52,6 +52,7 @@ #define bfd_pef_bfd_merge_sections      
 #define bfd_pef_bfd_is_group_section		    bfd_generic_is_group_section
 #define bfd_pef_bfd_discard_group                   bfd_generic_discard_group
 #define bfd_pef_section_already_linked	            _bfd_generic_section_already_linked
+#define bfd_pef_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define bfd_pef_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
 #define bfd_pef_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define bfd_pef_bfd_link_add_symbols                _bfd_generic_link_add_symbols
Index: bfd/ppcboot.c
===================================================================
--- bfd/ppcboot.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/ppcboot.c	2009-04-02 19:51:32.000000000 +0100
@@ -475,6 +475,7 @@ #define ppcboot_bfd_is_group_section bfd
 #define ppcboot_bfd_discard_group bfd_generic_discard_group
 #define ppcboot_section_already_linked \
   _bfd_generic_section_already_linked
+#define ppcboot_bfd_define_common_symbol bfd_generic_define_common_symbol
 #define ppcboot_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
 #define ppcboot_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
 #define ppcboot_bfd_link_add_symbols _bfd_generic_link_add_symbols
Index: bfd/som.c
===================================================================
--- bfd/som.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/som.c	2009-04-02 19:51:32.000000000 +0100
@@ -6349,6 +6349,7 @@ #define som_bfd_merge_sections		        
 #define som_bfd_is_group_section	        bfd_generic_is_group_section
 #define som_bfd_discard_group		        bfd_generic_discard_group
 #define som_section_already_linked              _bfd_generic_section_already_linked
+#define som_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define som_bfd_merge_private_bfd_data		_bfd_generic_bfd_merge_private_bfd_data
 #define som_bfd_copy_private_header_data	_bfd_generic_bfd_copy_private_header_data
 #define som_bfd_set_private_flags		_bfd_generic_bfd_set_private_flags
Index: bfd/srec.c
===================================================================
--- bfd/srec.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/srec.c	2009-04-02 19:51:32.000000000 +0100
@@ -1255,6 +1255,7 @@ #define srec_bfd_merge_sections         
 #define srec_bfd_is_group_section                 bfd_generic_is_group_section
 #define srec_bfd_discard_group                    bfd_generic_discard_group
 #define srec_section_already_linked               _bfd_generic_section_already_linked
+#define srec_bfd_define_common_symbol             bfd_generic_define_common_symbol
 #define srec_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
 #define srec_bfd_link_hash_table_free             _bfd_generic_link_hash_table_free
 #define srec_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
Index: bfd/tekhex.c
===================================================================
--- bfd/tekhex.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/tekhex.c	2009-04-02 19:51:32.000000000 +0100
@@ -943,6 +943,7 @@ #define tekhex_bfd_merge_sections       
 #define tekhex_bfd_is_group_section                 bfd_generic_is_group_section
 #define tekhex_bfd_discard_group                    bfd_generic_discard_group
 #define tekhex_section_already_linked               _bfd_generic_section_already_linked
+#define tekhex_bfd_define_common_symbol             bfd_generic_define_common_symbol
 #define tekhex_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
 #define tekhex_bfd_link_hash_table_free             _bfd_generic_link_hash_table_free
 #define tekhex_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
Index: bfd/versados.c
===================================================================
--- bfd/versados.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/versados.c	2009-04-02 19:51:32.000000000 +0100
@@ -808,6 +808,7 @@ #define versados_bfd_merge_sections     
 #define versados_bfd_is_group_section                 bfd_generic_is_group_section
 #define versados_bfd_discard_group                    bfd_generic_discard_group
 #define versados_section_already_linked               _bfd_generic_section_already_linked
+#define versados_bfd_define_common_symbol             bfd_generic_define_common_symbol
 #define versados_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
 #define versados_bfd_link_hash_table_free             _bfd_generic_link_hash_table_free
 #define versados_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
Index: bfd/vms.c
===================================================================
--- bfd/vms.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/vms.c	2009-04-02 19:51:32.000000000 +0100
@@ -144,6 +144,7 @@ #define vms_bfd_link_just_syms          
 #define vms_bfd_is_group_section          bfd_generic_is_group_section
 #define vms_bfd_discard_group             bfd_generic_discard_group
 #define vms_section_already_linked        _bfd_generic_section_already_linked
+#define vms_bfd_define_common_symbol      bfd_generic_define_common_symbol
 #define vms_bfd_copy_private_header_data  _bfd_generic_bfd_copy_private_header_data
 #define vms_get_synthetic_symtab          _bfd_nodynamic_get_synthetic_symtab
 
Index: bfd/xcoff-target.h
===================================================================
--- bfd/xcoff-target.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/xcoff-target.h	2009-04-02 19:51:32.000000000 +0100
@@ -57,6 +57,7 @@ #define _bfd_xcoff_bfd_gc_sections      
 #define _bfd_xcoff_bfd_merge_sections                  coff_bfd_merge_sections
 #define _bfd_xcoff_bfd_discard_group                   bfd_generic_discard_group
 #define _bfd_xcoff_section_already_linked              _bfd_generic_section_already_linked
+#define _bfd_xcoff_bfd_define_common_symbol            _bfd_xcoff_define_common_symbol
 #define _bfd_xcoff_bfd_link_split_section              coff_bfd_link_split_section
 
 #define CORE_FILE_P _bfd_dummy_target
Index: bfd/xsym.c
===================================================================
--- bfd/xsym.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/xsym.c	2009-04-02 19:51:32.000000000 +0100
@@ -46,6 +46,7 @@ #define bfd_sym_bfd_merge_sections      
 #define bfd_sym_bfd_is_group_section                bfd_generic_is_group_section
 #define bfd_sym_bfd_discard_group                   bfd_generic_discard_group
 #define bfd_sym_section_already_linked              _bfd_generic_section_already_linked
+#define bfd_sym_bfd_define_common_symbol            bfd_generic_define_common_symbol
 #define bfd_sym_bfd_link_hash_table_create          _bfd_generic_link_hash_table_create
 #define bfd_sym_bfd_link_hash_table_free            _bfd_generic_link_hash_table_free
 #define bfd_sym_bfd_link_add_symbols                _bfd_generic_link_add_symbols
Index: bfd/coff-rs6000.c
===================================================================
--- bfd/coff-rs6000.c	2009-04-01 19:57:15.000000000 +0100
+++ bfd/coff-rs6000.c	2009-04-02 19:51:32.000000000 +0100
@@ -4233,6 +4233,7 @@ const bfd_target rs6000coff_vec =
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
     _bfd_generic_section_already_linked,
+    _bfd_xcoff_define_common_symbol,
 
     /* Dynamic */
     _bfd_xcoff_get_dynamic_symtab_upper_bound,
@@ -4485,6 +4486,7 @@ const bfd_target pmac_xcoff_vec =
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
     _bfd_generic_section_already_linked,
+    _bfd_xcoff_define_common_symbol,
 
     /* Dynamic */
     _bfd_xcoff_get_dynamic_symtab_upper_bound,
Index: bfd/coff64-rs6000.c
===================================================================
--- bfd/coff64-rs6000.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/coff64-rs6000.c	2009-04-02 19:51:32.000000000 +0100
@@ -2805,6 +2805,7 @@ const bfd_target rs6000coff64_vec =
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
     _bfd_generic_section_already_linked,
+    _bfd_xcoff_define_common_symbol,
 
     /* Dynamic */
     _bfd_xcoff_get_dynamic_symtab_upper_bound,
@@ -3058,6 +3059,7 @@ const bfd_target aix5coff64_vec =
     bfd_generic_is_group_section,
     bfd_generic_discard_group,
     _bfd_generic_section_already_linked,
+    _bfd_xcoff_define_common_symbol,
 
     /* Dynamic */
     _bfd_xcoff_get_dynamic_symtab_upper_bound,
Index: bfd/linker.c
===================================================================
--- bfd/linker.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/linker.c	2009-04-02 20:39:48.000000000 +0100
@@ -3186,3 +3186,62 @@ _bfd_fix_excluded_sec_syms (bfd *obfd, s
 {
   bfd_link_hash_traverse (info->hash, fix_syms, obfd);
 }
+
+/*
+FUNCTION
+	bfd_generic_define_common_symbol
+
+SYNOPSIS
+	bfd_boolean bfd_generic_define_common_symbol
+	  (bfd *output_bfd, struct bfd_link_info *info,
+	   struct bfd_link_hash_entry *h);
+
+DESCRIPTION
+	Convert common symbol @var{h} into a defined symbol.
+	Return TRUE on success and FALSE on failure.
+
+.#define bfd_define_common_symbol(output_bfd, info, h) \
+.       BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h))
+.
+*/
+
+bfd_boolean
+bfd_generic_define_common_symbol (bfd *output_bfd,
+				  struct bfd_link_info *info ATTRIBUTE_UNUSED,
+				  struct bfd_link_hash_entry *h)
+{
+  unsigned int power_of_two;
+  bfd_vma alignment, size;
+  asection *section;
+
+  BFD_ASSERT (h != NULL && h->type == bfd_link_hash_common);
+
+  size = h->u.c.size;
+  power_of_two = h->u.c.p->alignment_power;
+  section = h->u.c.p->section;
+
+  /* Increase the size of the section to align the common symbol.
+     The alignment must be a power of two.  */
+  alignment = bfd_octets_per_byte (output_bfd) << power_of_two;
+  BFD_ASSERT (alignment != 0 && (alignment & -alignment) == alignment);
+  section->size += alignment - 1;
+  section->size &= -alignment;
+
+  /* Adjust the section's overall alignment if necessary.  */
+  if (power_of_two > section->alignment_power)
+    section->alignment_power = power_of_two;
+
+  /* Change the symbol from common to defined.  */
+  h->type = bfd_link_hash_defined;
+  h->u.def.section = section;
+  h->u.def.value = section->size;
+
+  /* Increase the size of the section.  */
+  section->size += size;
+
+  /* Make sure the section is allocated in memory, and make sure that
+     it is no longer a common section.  */
+  section->flags |= SEC_ALLOC;
+  section->flags &= ~SEC_IS_COMMON;
+  return TRUE;
+}
Index: bfd/targets.c
===================================================================
--- bfd/targets.c	2009-04-01 19:05:11.000000000 +0100
+++ bfd/targets.c	2009-04-02 20:13:16.000000000 +0100
@@ -441,7 +441,8 @@
 .  NAME##_bfd_merge_sections, \
 .  NAME##_bfd_is_group_section, \
 .  NAME##_bfd_discard_group, \
-.  NAME##_section_already_linked \
+.  NAME##_section_already_linked, \
+.  NAME##_bfd_define_common_symbol
 .
 .  int         (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
 .  bfd_byte *  (*_bfd_get_relocated_section_contents)
@@ -489,6 +490,10 @@
 .  void (*_section_already_linked) (bfd *, struct bfd_section *,
 .				    struct bfd_link_info *);
 .
+.  {* Define a common symbol.  *}
+.  bfd_boolean (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
+.					     struct bfd_link_hash_entry *);
+.
 .  {* Routines to handle dynamic symbols and relocs.  *}
 .#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
 .  NAME##_get_dynamic_symtab_upper_bound, \
Index: bfd/libcoff-in.h
===================================================================
--- bfd/libcoff-in.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/libcoff-in.h	2009-04-02 20:10:59.000000000 +0100
@@ -589,6 +589,8 @@ #define coff_get_section_contents_in_win
   (bfd *, struct bfd_link_info *);
 extern bfd_boolean _bfd_xcoff_bfd_final_link
   (bfd *, struct bfd_link_info *);
+extern bfd_boolean _bfd_xcoff_define_common_symbol
+  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
 extern bfd_boolean _bfd_ppc_xcoff_relocate_section
   (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    struct internal_reloc *, struct internal_syment *, asection **);
Index: bfd/xcofflink.c
===================================================================
--- bfd/xcofflink.c	2009-04-01 20:12:24.000000000 +0100
+++ bfd/xcofflink.c	2009-04-02 20:15:38.000000000 +0100
@@ -2471,6 +2471,21 @@ _bfd_xcoff_bfd_link_add_symbols (bfd *ab
     }
 }
 
+bfd_boolean
+_bfd_xcoff_define_common_symbol (bfd *output_bfd ATTRIBUTE_UNUSED,
+				 struct bfd_link_info *info ATTRIBUTE_UNUSED,
+				 struct bfd_link_hash_entry *harg)
+{
+  struct xcoff_link_hash_entry *h;
+
+  if (!bfd_generic_define_common_symbol (output_bfd, info, harg))
+    return FALSE;
+
+  h = (struct xcoff_link_hash_entry *) harg;
+  h->flags |= XCOFF_DEF_REGULAR;
+  return TRUE;
+}
+
 /* If symbol H has not been interpreted as a function descriptor,
    see whether it should be.  Set up its descriptor information if so.  */
 
@@ -3330,19 +3345,6 @@ xcoff_post_gc_symbol (struct xcoff_link_
   if (h->flags & XCOFF_RTINIT)
     return TRUE;
 
-  /* If this is a final link, and the symbol was defined as a common
-     symbol in a regular object file, and there was no definition in
-     any dynamic object, then the linker will have allocated space for
-     the symbol in a common section but the XCOFF_DEF_REGULAR flag
-     will not have been set.  */
-  if (h->root.type == bfd_link_hash_defined
-      && (h->flags & XCOFF_DEF_REGULAR) == 0
-      && (h->flags & XCOFF_REF_REGULAR) != 0
-      && (h->flags & XCOFF_DEF_DYNAMIC) == 0
-      && (bfd_is_abs_section (h->root.u.def.section)
-	  || (h->root.u.def.section->owner->flags & DYNAMIC) == 0))
-    h->flags |= XCOFF_DEF_REGULAR;
-
   /* We don't want to garbage collect symbols which are not defined in
      XCOFF files.  This is a convenient place to mark them.  */
   if (xcoff_hash_table (ldinfo->info)->gc
Index: bfd/bfd-in2.h
===================================================================
--- bfd/bfd-in2.h	2009-04-01 19:45:02.000000000 +0100
+++ bfd/bfd-in2.h	2009-04-02 20:13:27.000000000 +0100
@@ -5455,7 +5455,8 @@ #define BFD_JUMP_TABLE_LINK(NAME) \
   NAME##_bfd_merge_sections, \
   NAME##_bfd_is_group_section, \
   NAME##_bfd_discard_group, \
-  NAME##_section_already_linked \
+  NAME##_section_already_linked, \
+  NAME##_bfd_define_common_symbol
 
   int         (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
   bfd_byte *  (*_bfd_get_relocated_section_contents)
@@ -5503,6 +5504,10 @@ #define BFD_JUMP_TABLE_LINK(NAME) \
   void (*_section_already_linked) (bfd *, struct bfd_section *,
                                    struct bfd_link_info *);
 
+  /* Define a common symbol.  */
+  bfd_boolean (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
+                                            struct bfd_link_hash_entry *);
+
   /* Routines to handle dynamic symbols and relocs.  */
 #define BFD_JUMP_TABLE_DYNAMIC(NAME) \
   NAME##_get_dynamic_symtab_upper_bound, \
@@ -5567,6 +5572,13 @@ void bfd_section_already_linked (bfd *ab
 #define bfd_section_already_linked(abfd, sec, info) \
        BFD_SEND (abfd, _section_already_linked, (abfd, sec, info))
 
+bfd_boolean bfd_generic_define_common_symbol
+   (bfd *output_bfd, struct bfd_link_info *info,
+    struct bfd_link_hash_entry *h);
+
+#define bfd_define_common_symbol(output_bfd, info, h) \
+       BFD_SEND (output_bfd, _bfd_define_common_symbol, (output_bfd, info, h))
+
 /* Extracted from simple.c.  */
 bfd_byte *bfd_simple_get_relocated_section_contents
    (bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);
Index: bfd/libbfd.h
===================================================================
--- bfd/libbfd.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/libbfd.h	2009-04-02 20:12:06.000000000 +0100
@@ -421,6 +421,9 @@ #define _bfd_nolink_bfd_link_split_secti
   ((bfd_boolean (*) (bfd *, struct bfd_section *)) bfd_false)
 #define _bfd_nolink_section_already_linked \
   ((void (*) (bfd *, struct bfd_section *, struct bfd_link_info *)) bfd_void)
+#define _bfd_nolink_bfd_define_common_symbol \
+  ((bfd_boolean (*) (bfd *, struct bfd_link_info *, \
+		     struct bfd_link_hash_entry *)) bfd_false)
 
 /* Routines to use for BFD_JUMP_TABLE_DYNAMIC for targets which do not
    have dynamic symbols or relocs.  Use BFD_JUMP_TABLE_DYNAMIC
Index: bfd/libcoff.h
===================================================================
--- bfd/libcoff.h	2009-04-01 19:05:11.000000000 +0100
+++ bfd/libcoff.h	2009-04-02 20:12:03.000000000 +0100
@@ -593,6 +593,8 @@ #define coff_get_section_contents_in_win
   (bfd *, struct bfd_link_info *);
 extern bfd_boolean _bfd_xcoff_bfd_final_link
   (bfd *, struct bfd_link_info *);
+extern bfd_boolean _bfd_xcoff_define_common_symbol
+  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
 extern bfd_boolean _bfd_ppc_xcoff_relocate_section
   (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    struct internal_reloc *, struct internal_syment *, asection **);
Index: ld/ldlang.c
===================================================================
--- ld/ldlang.c	2009-04-01 19:05:10.000000000 +0100
+++ ld/ldlang.c	2009-04-02 20:10:03.000000000 +0100
@@ -5641,27 +5641,9 @@ lang_one_common (struct bfd_link_hash_en
     return TRUE;
 
   section = h->u.c.p->section;
-
-  /* Increase the size of the section to align the common sym.  */
-  section->size += ((bfd_vma) 1 << (power_of_two + opb_shift)) - 1;
-  section->size &= (- (bfd_vma) 1 << (power_of_two + opb_shift));
-
-  /* Adjust the alignment if necessary.  */
-  if (power_of_two > section->alignment_power)
-    section->alignment_power = power_of_two;
-
-  /* Change the symbol from common to defined.  */
-  h->type = bfd_link_hash_defined;
-  h->u.def.section = section;
-  h->u.def.value = section->size;
-
-  /* Increase the size of the section.  */
-  section->size += size;
-
-  /* Make sure the section is allocated in memory, and make sure that
-     it is no longer a common section.  */
-  section->flags |= SEC_ALLOC;
-  section->flags &= ~SEC_IS_COMMON;
+  if (!bfd_define_common_symbol (link_info.output_bfd, &link_info, h))
+    einfo (_("%P%F: Could not define common symbol `%T': %E\n"),
+	   h->root.string);
 
   if (config.map_file != NULL)
     {
Index: ld/testsuite/ld-powerpc/aix-export-2.s
===================================================================
--- /dev/null	2009-04-02 20:41:37.503807747 +0100
+++ ld/testsuite/ld-powerpc/aix-export-2.s	2009-04-02 19:51:32.000000000 +0100
@@ -0,0 +1,1 @@
+	.comm	x,4
Index: ld/testsuite/ld-powerpc/aix-export-2.nd
===================================================================
--- /dev/null	2009-04-02 20:41:37.503807747 +0100
+++ ld/testsuite/ld-powerpc/aix-export-2.nd	2009-04-02 19:51:32.000000000 +0100
@@ -0,0 +1,1 @@
+0*10000000 B x
Index: ld/testsuite/ld-powerpc/aix52.exp
===================================================================
--- ld/testsuite/ld-powerpc/aix52.exp	2009-04-01 20:07:51.000000000 +0100
+++ ld/testsuite/ld-powerpc/aix52.exp	2009-04-02 19:51:32.000000000 +0100
@@ -128,6 +128,10 @@ set aix52tests {
      {{objdump -dj.data aix-export-1-full.dd}}
      "aix-export-1-full.so"}
 
+    {"Export test 2" "-shared -bexpall"
+     {} {aix-export-2.s}
+     {{nm -D aix-export-2.nd}} "aix-export-2.so"}
+
     {"Garbage collection test 1"
      "-shared -binitfini:init_function:fini_function -bE:aix-gc-1.ex"
      "" {aix-gc-1.s}


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