Menu

#604 fix for elftoolchain objcopy is missing --add-symbol

RELEASE_0_7_1
accepted
None
2021-04-05
2021-03-27
No

This is a patch to fix

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=245024

elftoolchain objcopy is missing --add-symbol

Fix:

Two fields were added to struct elfcopy in elfcopy.h. An integer to keep track
of the number of symbols to add and a linked list to store the wanted symbols.
Two structures were added to elfcopy.h to support adding symbols: struct
sym_add and struct symbol.

In main.c, if --add-symbol is passed on the command line, it is parsed and the
add symbols linked list populated. In create_file(), which does the bulk of
the work, if there are symbols to add, a temporary file is created
(addtmpfile), ifd is copied into addtmpfile and ifd closed. Symbols are added
to addtmpfile via function calls located in symbols.c. addtmpfile is closed
and reopened to add the new symbols. ifd is reopened using addtmpfile and the
add symbols linked list and other resources cleaned up.

Tests were added to test/elfcopy/tc directory: elfcopy-addsymbol-[1-4]

This was developed and tested with FreeBSD-CURRENT and compiles and tests pass
with Ubuntu-20.4, but other BSDs/Linux distributions have not been tested.

The updated manpage for elfcopy describes the behavior of --add-symbol:

--add-symbol name=[section:]value[,flags]
Add a new symbol to .symtab and, if needed, .strtab.
Supported flags are: 'default', 'hidden', 'protected',
'global', 'local', 'unique-object', 'weak', 'common', 'file',
'function', 'indirect-function', 'object', 'section' and 'tls'.
The flag 'before=othersym' will insert a new symbol before
'othersym'. If 'othersym' or the 'section' is not found,
elfcopy will fail. Other flags are accepted, but ignored.
Can be added multiple times. The default is to add a global
absolute symbol to the end of the symbol table.

1 Attachments

Discussion

  • Joseph Koshy

    Joseph Koshy - 2021-04-05
    • status: new --> accepted
    • assigned_to: Joseph Koshy
     
  • Joseph Koshy

    Joseph Koshy - 2021-04-05

    A patch that comes with a test and documentation changes is rare indeed! I'll take a look over the next few days.

     

Log in to post a comment.