Bug 241437 - objcopy --add-section doesn't work
Summary: objcopy --add-section doesn't work
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
Depends on:
Reported: 2019-10-23 15:36 UTC by Gleb Popov
Modified: 2020-03-20 15:50 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Gleb Popov freebsd_committer 2019-10-23 15:36:22 UTC
I have created a simple C program:

# cat test.c 
int main(int argc, char* argv[]) {return 0;}

Now I want to embed some data (its own LLVM bitcode, specifically) as an ELF section. I do:

# clang test.c -c -o test.c.o
# clang -emit-llvm -c test.c -o test.c.bc

Now, if I run

# objcopy --add-section .llvm_bc=test.c.bc test.c.o

I get 0 exit code, but the section doesn't get added:

# readelf -S test.c.o | grep llvm

However, if I **just run the same command twice**

# objcopy --add-section .llvm_bc=test.c.bc test.c.o

the section gets added successfully.
Comment 1 Ed Maste freebsd_committer 2019-10-23 20:46:51 UTC
Confirmed on -CURRENT around r348071
Comment 2 Ed Maste freebsd_committer 2020-02-07 21:08:12 UTC
See https://reviews.freebsd.org/D23571
Comment 3 Ed Maste freebsd_committer 2020-02-13 18:55:48 UTC
Staged in my WIP tree here: https://github.com/emaste/freebsd/commit/5bf5fba0823c17399393d341b74cb455a08ab946
Comment 4 commit-hook freebsd_committer 2020-03-20 15:50:42 UTC
A commit references this bug:

Author: emaste
Date: Fri Mar 20 15:50:38 UTC 2020
New revision: 359166
URL: https://svnweb.freebsd.org/changeset/base/359166

  objcopy: add new sections also when there is no .shstrtab

  Previously objcopy (elfcopy) --add-sections inserted new sections before
  .shstrtab, but omitted them if there was no .shstrtab.

  Now, after processing existing sections add new sections if they were
  not yet added.

  PR:		241437
  Reported by:	arrowd
  Submitted by:	Tiger Gao <tig@FreeBSDFoundation.org>
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D23571