Bug 5543 - Assembler crashes on .set
Summary: Assembler crashes on .set
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-04 18:42 UTC by H.J. Lu
Modified: 2008-03-03 15:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Fix for bug 5543: disallow symbols .set to register name to be .global (515 bytes, patch)
2008-02-21 12:00 UTC, Denis Vlasenko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2008-01-04 18:42:24 UTC
[hjl@gnu-6 gas]$ cat y.s
        .globl  foo
        .set    foo,(%eax)
[hjl@gnu-6 gas]$ as --32 -o y.o y.s
as: BFD (Linux/GNU Binutils) 2.18.50.0.4.20071229 assertion fail
/net/gnu-13/export/linux/src/binutils/binutils/bfd/elf.c:6405
as: BFD (Linux/GNU Binutils) 2.18.50.0.4.20071229 internal error, aborting at
/net/gnu-13/export/linux/src/binutils/binutils/bfd/elfcode.h line 221 in
bfd_elf32_swap_symbol_out

as: Please report this bug.

Is ".set    foo,(%eax)" valid?
Comment 1 Denis Vlasenko 2008-02-20 00:00:29 UTC
bfd/elf.c:

static bfd_boolean
swap_out_syms (bfd *abfd,
               struct bfd_strtab_hash **sttp,
               int relocatable_p) {
...
                  /* Writing this would be a hell of a lot easier if
                     we had some decent documentation on bfd, and
                     knew what to expect of the library, and what to
                     demand of applications.  For example, it
                     appears that `objcopy' might not set the
                     section of a symbol to be a section that is
                     actually in the output file.  */
fprintf(stderr, "vda: sec->name '%s'\n", sec->name);
                  sec2 = bfd_get_section_by_name (abfd, sec->name);
                  if (sec2 == NULL)
                    {
                      _bfd_error_handler (_("\
Unable to find equivalent output section for symbol '%s' from section '%s'"),
                                          syms[idx]->name ? syms[idx]->name :
"<Local sym>",
                                          sec->name);
                      bfd_set_error (bfd_error_invalid_operation);
                      _bfd_stringtab_free (stt);
                      return FALSE;
                    }

fprintf(stderr, "vda: sec2->name '%s'\n", sec2->name);
                  shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
                  BFD_ASSERT (shndx != -1);

Both print the same:

vda: sec->name '*GAS `reg' section*'
vda: sec2->name '*GAS `reg' section*'

This section is created here: gas/as.c:

static void perform_an_assembly_pass (int argc, char ** argv) {
...
  reg_section = subseg_new ("*GAS `reg' section*", 0);

and is removed in gas/write.c:

void write_object_file (void) {
...
    bfd_section_list_remove (stdoutput, reg_section);


write_object_file() is invoked in main() way before xexit() ->
-> bfd_close()
-> BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd)))
-> _bfd_elf_write_object_contents
-> _bfd_elf_compute_section_file_positions
-> swap_out_syms
Comment 2 H.J. Lu 2008-02-20 23:39:53 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2008-02/msg00199.html
Comment 3 Denis Vlasenko 2008-02-21 11:58:17 UTC
Sorry H.J. Lu, I tried the patch and both test programs:

        .globl  foo
        .set    foo,(%eax)

and

        .set    foo,(%eax)
        .globl  foo

still produced this message:

./gas/as-new: BFD (GNU Binutils) 2.18.50.20080219 assertion fail
../../bfd/elf.c:6344
./gas/as-new: BFD (GNU Binutils) 2.18.50.20080219 internal error, aborting at
../../bfd/elfcode.h line 221 in bfd_elf32_swap_symbol_out
./gas/as-new: Please report this bug.
Comment 4 Denis Vlasenko 2008-02-21 12:00:02 UTC
Created attachment 2279 [details]
Fix for bug 5543: disallow symbols .set to register name to be .global

Behavior with this patch:

	.globl	foo
	.set	foo,(%eax)

z.s: Assembler messages:
z.s:2: Error: attempt to produce global register symbol


and

	.set	foo,(%eax)
	.globl	foo

z2.s: Assembler messages:
z2.s:2: Error: cannot make register symbol global
Comment 5 H.J. Lu 2008-03-03 15:57:12 UTC
Fixed by

http://sourceware.org/ml/binutils/2008-03/msg00015.html