bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/27229] New: Writing symbols section - example code does no


From: karthik.eu at outlook dot com
Subject: [Bug binutils/27229] New: Writing symbols section - example code does not work
Date: Sat, 23 Jan 2021 19:19:48 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27229

            Bug ID: 27229
           Summary: Writing symbols section - example code does not work
           Product: binutils
           Version: 2.35.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: karthik.eu at outlook dot com
  Target Milestone: ---

Created attachment 13149
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13149&action=edit
object file

I am following the example at
https://sourceware.org/binutils/docs-2.35/bfd/Writing-Symbols.html#Writing-Symbols

My code is slightly modified and I expect it to produce a pe-x86-64 COFF object
file.

```
    bfd_init();
    auto *abfd = bfd_openw("test.obj", "pe-x86-64");
    my_assert(bfd_set_format(abfd, bfd_object));
    my_assert(bfd_set_file_flags(abfd, HAS_RELOC | HAS_SYMS));

    auto symbol = bfd_make_empty_symbol(abfd);
    symbol->name = "my_data";
    symbol->section = bfd_make_section_old_way(abfd, ".data");
    symbol->flags = BSF_GLOBAL;
    symbol->value = 0xab;

    asymbol *symbols[] = { symbol, nullptr };
    bfd_set_symtab(abfd, symbols, 1);

    bfd_close(abfd);

```

Both `nm` and `objdump` from the same mingw64 environment do not recognize this
file.

> C:\msys64\mingw64\bin\nm.exe: test.obj: file format not recognized

On the other hand, `dumpbin` utility on windows can read it

> Dump of file test.obj
> File Type: COFF OBJECT
>  Summary
>           0 .data

When I use `pei-x86-64` instead of `pe-x86-64`, the file utility reads my file

> test.obj: PE Unknown PE signature 0x0 (stripped to external PDB), for MS 
> Windows

I tried to read the same with

```
    bfd *abfd = bfd_openr(test_bin, nullptr);
    bool isCorrectFormat = bfd_check_format(abfd, bfd_object);
```

and this also failed with `bfd_get_error() -> bfd_error_file_not_recognized`.

What I am doing wrong? Did I misunderstand the target names?

I am trying to generate an object file with some data in the `.data` section
and I want mingw-w64-x86_64-binutils tools to recognize this file.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]