[PATCH] D67144: [llvm-objcopy] Default --output-target to --input-target when unspecified

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 03:34:36 PDT 2019


MaskRay added a comment.

binutils-gdb/binutils/NEWS says

  * New command-line switch to objcopy -B (or --binary-architecture) which sets
    the architecture of the output file to the given argument.  This option only
    makes sense, if the input target is binary.  Otherwise it is ignored.
    By Stefan Geuken.

I assume it means `-B` is only useful when `-I binary` is used. Now there are 2 cases:

- `-I binary -O binary` => it is a copy. -B is ignored.
- `-I binary -O elf64-x86-64` => elf64-x86-64 makes the output little-endian and 64-bit, but `e_machine` is not set. `-B i386:x86-64` is supposed to set the `e_machine` field. This means if `-I binary` is used and `-O` is not `binary`, `-B` should always be set. I don't know why it behaves that way. I guess we may be able to ignore `-B` entirely. I'll do that in the next patch.

  % file b.o
  b.o: ELF 64-bit LSB relocatable, no machine, version 1 (SYSV), not stripped



================
Comment at: test/tools/llvm-objcopy/ELF/binary-input-error.test:3-4
 
-# RUN: not llvm-objcopy -I binary %t.txt %t.o 2>&1 \
-# RUN:   | FileCheck %s --check-prefix=MISSING-BINARY-ARCH
-
----------------
jhenderson wrote:
> This is valid behaviour now, right? We need a test case to show this works.
Added a test to binary-input-and-output.test

```
## If -O is not specified, it defaults to -I, i.e. "binary".
# RUN: llvm-objcopy -I binary %t.txt %t.3.txt
# RUN: cmp %t.txt %t.3.txt
```


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67144/new/

https://reviews.llvm.org/D67144





More information about the llvm-commits mailing list