This is the mail archive of the binutils@sources.redhat.com 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: copy_private_bfd_data in bfd/elf.c question


Hello,

    I am still looking at code in copy_private_bfd_data()
which is causing problems with strip and objcopy on
IA-64 HP-UX.   When the binutils version of strip and
objcopy are used on HP-UX, the resulting program gets
a segmentation violation when it is executed.  As Andreas
pointed out in:

http://sources.redhat.com/ml/binutils/2002-06/msg00762.html

the cause for the segmentation violation was because strip
and objcopy were changing the offset of the .hash section.  The
change in offset happens in assign_file_positions_for_segments()
which uses the segment's p_paddr field to calcuate the new position.
Unfortunately, the new position is not correctly aligned which
causes the segmentation violation.

    The HP Linker sets the p_paddr field of all of the segments to 0.
There is code in copy_private_bfd_data() which detects this and
tries to "fix" things.  From the comments, it appears that this is
done because the Solaris linker also sets p_paddr to 0.  The
code in copy_private_bfd_data() is the following:

        /* The Solaris native linker always sets p_paddr to 0.
           We try to catch that case here, and set it to the
           correct value.  */
        if (segment->p_paddr == 0
            && segment->p_vaddr != 0
            && isec == 0
            && output_section->lma != 0
            && (output_section->vma == (segment->p_vaddr
                             + (map->includes_filehdr
                             ? iehdr->e_ehsize
                             : 0)
                             + (map->includes_phdrs
                             ? (iehdr->e_phnum
                             * iehdr->e_phentsize)
                            : 0))))
         map->p_paddr = segment->p_vaddr;


            I am not sure why this code was needed for Solaris but
it needs to be disabled for HP-UX on IA-64.  According to my
ELF Document it says that the p_paddr field of the program
header (segment) is reserved for systems with physical addressing.
HP-UX is not such a system and therefore I believe that p_paddr should
be left as 0.  (It probably should be left as 0 for all systems which
do not do physical addressing, but that is another matter).  In
any case, I tried to work around the fact that p_paddr is
recalculated by playing with section alignment but I ran into further
problems in assign_file_positons_for_segments().  I believe
the real fix is to disable setting p_paddr in copy_private_bfd_data().

    I do have a fix for this which works on HP-UX.  However, the
fix involves a compile-time check and I understand that compile-time
checks are discouraged in bfd.  Is there a runtime check that
would do the same thing or do I need my own version of
copy_private_bfd_data()?  Here is what I want to do:

#ifndef NO_PHYSICAL_ADDRESSING
              /* The Solaris native linker always sets p_paddr to 0.
                 We try to catch that case here, and set it to the
                 correct value.  */
              if (segment->p_paddr == 0
                  && segment->p_vaddr != 0
                  && isec == 0
                  && output_section->lma != 0
                  && (output_section->vma == (segment->p_vaddr
                                              + (map->includes_filehdr
                                                 ? iehdr->e_ehsize
                                                 : 0)
                                              + (map->includes_phdrs
                                                 ? (iehdr->e_phnum
                                                    *
iehdr->e_phentsize)
                                                 : 0))))
                map->p_paddr = segment->p_vaddr;
#endif
              /* Match up the physical address of the segment with the
                 LMA address of the output section.  */
              if (IS_CONTAINED_BY_LMA (output_section, segment,
map->p_paddr)
                  || IS_CONTAINED_BY_FILEPOS (section, segment, bed)
#ifndef NO_PHYSICAL_ADDRESSING
                  || IS_COREFILE_NOTE (segment, section))
#else
                  || IS_COREFILE_NOTE (segment, section)
                  || IS_CONTAINED_BY_VMA (output_section, segment))
#endif

                {
                  if (matching_lma == 0)
                    matching_lma = output_section->lma;

                  /* We assume that if the section fits within the
segment
                     then it does not overlap any other section within
that
                     segment.  */
                  map->sections[isec ++] = output_section;
                }
              else if (suggested_lma == 0)
                suggested_lma = output_section->lma;
            }
        }


Is there an acceptable way to do this?

Thanks so much!

Reva Cuthbertson
reva@cup.hp.com




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