Bug 26356 - FAIL: objcopy --reverse-bytes
Summary: FAIL: objcopy --reverse-bytes
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2020-08-08 15:23 UTC by John David Anglin
Modified: 2020-08-27 20:57 UTC (History)
0 users

See Also:
Host: hppa2.0w-hp-hpux11.11
Target: hppa2.0w-hp-hpux11.11
Build: hppa2.0w-hp-hpux11.11
Last reconfirmed:

Patch (683 bytes, text/plain)
2020-08-09 20:10 UTC, John David Anglin
Patch to fix dollar-sign quoting for binutils tests (442 bytes, patch)
2020-08-21 00:50 UTC, John David Anglin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2020-08-08 15:23:28 UTC
/mnt/gnu/binutils/objdir/binutils/objcopy  -j \$DATA\$ --reverse-bytes=4 tmpdir/
bintest.o tmpdir/bintest.o-reversed
Executing on host: /mnt/gnu/binutils/objdir/binutils/objcopy  -j \\$DATA\\$ --re
verse-bytes=4 tmpdir/bintest.o tmpdir/bintest.o-reversed   (timeout = 300)
spawn failed

Program causes segmentation fault.

-bash-4.4$ ./objcopy -j \$DATA\$ --reverse-bytes objcopy.o xxx.o
./objcopy: number of bytes to reverse must be positive and even
-bash-4.4$ ./objcopy -j \$DATA\$ --reverse-bytes=4 objcopy.o xxx.o
Segmentation fault (core dumped)
-bash-4.4$ gdb -c core objcopy
GNU gdb (GDB) 7.9.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "hppa2.0w-hp-hpux11.11".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from objcopy...done.
[New process 6052895]

warning: Private mapping of shared library text was not specified
by the executable; setting a breakpoint in a shared library which
is not privately mapped will not work.  See the HP-UX 11i v3 chatr
manpage for methods to privately map shared library text.
Unable to write __dld_flags.
(gdb) bt
#0  som_prep_headers (abfd=0x40014108) at ../../src/bfd/som.c:2678
#1  0x00047fd8 in som_set_section_contents (abfd=0x40014108, section=0x0,
    location=0x40027150, offset=0, count=2320) at ../../src/bfd/som.c:5711
#2  0x00036c58 in bfd_set_section_contents (abfd=0x40014108,
    section=0x40023fd0, location=0x40027150, offset=0, count=2320)
    at ../../src/bfd/section.c:1520
#3  0x00010ca4 in copy_section (ibfd=0xffffffff, isection=0x40020e08,
    obfdarg=0x40014108) at ../../src/binutils/objcopy.c:4430
#4  0x00036a4c in bfd_map_over_sections (abfd=0x40013048,
    operation=@0x400093ca: 0x109c8 <copy_section>, user_storage=0x40014108)
    at ../../src/bfd/section.c:1379
#5  0x00012a24 in copy_object (ibfd=0x40013048, obfd=0x40014108,
    input_arch=0x4002ff00) at ../../src/binutils/objcopy.c:3266
#6  0x000141fc in copy_file (input_filename=0x7eff0026 "objcopy.o",
    output_filename=0x7eff0030 "xxx.o", input_target=0x40014108 "@\002/\240@",
    output_target=0x89384 <__PRETTY_FUNCTION__.10416+24> "som", input_arch=0x0)
    at ../../src/binutils/objcopy.c:3831
#7  0x00016d5c in main (argc=1818324583, argv=0x6f70742f)
    at ../../src/binutils/objcopy.c:5892
(gdb) disass $pc-16,$pc+16
Dump of assembler code from 0x464bc to 0x464dc:
   0x000464bc <som_prep_headers+148>:   cmpib,=,n 0,ret0,0x465a4 <som_prep_headers+380>
   0x000464c0 <som_prep_headers+152>:   ldw 4(ret0),ret0
   0x000464c4 <som_prep_headers+156>:   cmpb,= r3,ret0,0x465bc <som_prep_headers+404>
   0x000464c8 <som_prep_headers+160>:   ldo 40(ret0),ret0
=> 0x000464cc <som_prep_headers+164>:   ldw 0(ret0),ret0
   0x000464d0 <som_prep_headers+168>:   cmpb,= r3,ret0,0x465bc <som_prep_headers+404>
   0x000464d4 <som_prep_headers+172>:   copy r8,r25
   0x000464d8 <som_prep_headers+176>:   b,l 0x353d8 <bfd_zalloc>,rp
End of assembler dump.
(gdb) p/x $ret0
$1 = 0x40

static bfd_boolean
som_is_space (asection *section)
  /* If no copy data is available, then it's neither a space nor a
     subspace.  */
  if (som_section_data (section)->copy_data == NULL)
    return FALSE;

  /* If the containing space isn't the same as the given section,
     then this isn't a space.  */
  if (som_section_data (section)->copy_data->container != section
      && (som_section_data (section)->copy_data->container->output_section
          != section))
    return FALSE;

  /* OK.  Must be a space.  */
  return TRUE;

Looks like som_section_data (section)->copy_data->container is NULL.

This bug has been around for some time.
Comment 1 John David Anglin 2020-08-09 20:10:58 UTC
Created attachment 12755 [details]

The change to som.c fix the segmentation fault running objcopy.  However, I'm
not sure that this isn't just papering over a higher level problem.

After this I found we had an extra backslash before the the '$' characters in $DATA$. I revised the get_standard_section_names proc to work around this.

After this, the pr23633 started to fail so I xfailed it on som.

The reversed-bytes test still doesn't pass. $DATA$ turns into a space.  It should be a subspace in $PRIVATE$.

The "objcopy object (simple copy)" fails here:
tmpdir/bintest.o tmpdir/copy.o differ: char 168, line 1

I believe this is because the 'O' bit gets set in $LIT$ and $MILLICODE$:

-bash-4.4$ odump -subspaces tmpdir/bintest.o

Subspace dictionary for tmpdir/bintest.o:

Sub Sp AC RDCLQIOENKT Key Loc/Init InitLn  Start    Len  Align Fixups Name

  0  0 2c ...L0.O....  24 000001ec 000010 00000000 000010  8    0   4 $CODE$
  1  0 2c ...L0......  16 000001fc 000000 00000000 000000  8    4   0 $LIT$
  2  0 2c ...L0......   8 000001fc 000000 00000000 000000  8    4   0 $MILLICODE$
  3  1 1f ...L1......  24 000001fc 000008 00000000 000008  8    4   1 $DATA$
  4  1 1f ...L1......  80 00000000 000000 00000000 000000  8   -1   0 $BSS$

-bash-4.4$ odump -subspaces tmpdir/copy.o

Subspace dictionary for tmpdir/copy.o:

Sub Sp AC RDCLQIOENKT Key Loc/Init InitLn  Start    Len  Align Fixups Name

  0  0 2c ...L0.O....  24 000001ec 000008 00000000 000008  8    0   1 $CODE$
  1  0 2c ...L0.O....  16 000001f4 000000 00000000 000000  8   -1   0 $LIT$
  2  0 2c ...L0.O....   8 000001f4 000000 00000000 000000  8   -1   0 $MILLICODE$
  3  1 1f ...L1......  24 000001f4 000000 00000000 000000  8   -1   0 $DATA$
  4  1 1f ...L1......  80 00000000 000000 00000000 000000  8   -1   0 $BSS$

The O bit indicates code only (no literal data), so it is incorrectly set by

There's also differences in fixup indexes and counts.
Comment 2 John David Anglin 2020-08-10 20:26:23 UTC
There is this function som_bfd_copy_private_section_data() which is never called but it looks like it should be called when objcopy is run.  This is the reason
container is NULL in the output section.  It never got copied from the input.

From the ChangeLogs, it looks like it used to be called.

Alan, do you have a suggestion on what to change so it is called?
Comment 3 Alan Modra 2020-08-11 00:18:50 UTC
(In reply to John David Anglin from comment #2)
> There is this function som_bfd_copy_private_section_data() which is never
> called but it looks like it should be called when objcopy is run.
But it *is* called.
Comment 4 John David Anglin 2020-08-11 11:58:38 UTC
Hi Alan,

You are correct.  som_bfd_copy_private_section_data() is called once for the
subspace $DATA$.  This code is problematic:

  /* Reparent if necessary.  */
  if (som_section_data (osection)->copy_data->container)
    som_section_data (osection)->copy_data->container =
      som_section_data (osection)->copy_data->container->output_section;

After the memcpy, som_section_data (osection)->copy_data->container points to the asection for $PRIVATE$.

som_section_data(osection)->copy_data->container->output_section is NULL.

Setting som_section_data (osection)->copy_data->container to NULL causes the
segmentation fault in som_is_space().  It is inlined in som_prep_headers().
osection no longer points to a valid space or subspace.  isection pointed
to a valid subspace.

If som_is_space() and som_is_subspace() are modified to return false when
the container is NULL, the output doesn't contain $PRIVATE$ and $DATA$, and
the test fails.

I'm thinking we need to copy both the containing space for $DATA$ and $DATA$.
Comment 5 John David Anglin 2020-08-21 00:50:02 UTC
Created attachment 12785 [details]
Patch to fix dollar-sign quoting for binutils tests

The get_standard_section_names proc returns section names on the SOM target
that are already.  This can't be changed without breaking various gas tests.
Double quoting results in an incorrect command.

This change removes any existing dollar-sign quotes before re-quoting.

Still working on problems in som.c.
Comment 6 cvs-commit@gcc.gnu.org 2020-08-27 15:25:54 UTC
The master branch has been updated by John David Anglin <danglin@sourceware.org>:


commit 9e7ed8b080afa19fff25244913594f95af282657
Author: John David Anglin <danglin@gcc.gnu.org>
Date:   Thu Aug 27 15:25:03 2020 +0000

    Fix PR binutils/26356 on hppa*-*-hpux*.
            PR 26356
            * som.c (som_bfd_copy_private_section_data): Issue error when a
            subspace is specified without its containing space.
            * testsuite/binutils-all/objcopy.exp (objcopy --reverse-bytes): Add
            "-j $PRIVATE$" to command on hppa*-*-hpux*.
            * testsuite/lib/utils-lib.exp (default_binutils_run): Remove existing
            dollar-sign quotes before quoting.  Do this prior to generating log
Comment 7 John David Anglin 2020-08-27 20:57:02 UTC