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]

elf section type & objcopy


H.J., Nick,

Back in 2006 H.J. applied this bfd patch:
2006-04-26  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/2593
	* elf.c (_bfd_elf_new_section_hook): Don't set section ELF type
	and flags if its BFD flags have been set.
	(_bfd_elf_init_private_section_data): Don't copy the output ELF
	section type from input if it has been set to something
	different.

The mailing list thread is http://sourceware.org/ml/binutils/2006-04/msg00302.html

this breaks the following behaviour of objcopy:
  objcopy --add-section .note=some-file in.o out.o

previously, the new .note section would get a section type of NOTES, because _bfd_elf_get_sec_type_attr got called and checks for special section names. The above patch causes that not to happen, as objcopy used make_section_with_flags, passing non-zero flags in. Yes, it's taken this long for someone to notice :)

The attached flag also sets SEC_LINKER_CREATED to force checking the section name and restores the original behaviour.

I've not checked whether setting the section type from the name this way is documented -- it should be if it is what we want to happen. I also need to create a testcase for this patch.

I have verified that the attached patch causes no regressions -- HJ's test cases still pass, so I guess I've not broken the above fix.

Am I heading in the right direction?

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery

2010-01-28  Nathan Sidwell  <nathan@codesourcery.com>

	* objcopy (copy_object): Set SEC_LINKER_CREATED when adding
	sections.

Index: objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.141
diff -c -3 -p -r1.141 objcopy.c
*** objcopy.c	20 Jan 2010 00:09:13 -0000	1.141
--- objcopy.c	28 Jan 2010 16:59:13 -0000
*************** copy_object (bfd *ibfd, bfd *obfd, const
*** 1608,1614 ****
  	    }
  	  else
  	    {
! 	      padd->section = bfd_make_section_with_flags (obfd, padd->name, flags);
  	      if (padd->section == NULL)
  		{
  		  bfd_nonfatal_message (NULL, obfd, NULL,
--- 1608,1615 ----
  	    }
  	  else
  	    {
! 	      padd->section = bfd_make_section_with_flags
! 		(obfd, padd->name, flags | SEC_LINKER_CREATED);
  	      if (padd->section == NULL)
  		{
  		  bfd_nonfatal_message (NULL, obfd, NULL,

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