<div dir="ltr"><div><div><div>Hi,<br><br></div>At the moment, we've only added support for 64-bit Little Endian ELF to llvm-objcopy, but I'm pretty sure most of the code should be able to handle 32-bit ELF as well, with a patch such as the one you've attached. Jake Ehrlich (CC'ed), who is the main developer on llvm-objcopy should be able to give you a more complete answer.<br><br></div>Regards,<br><br></div>James<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 November 2017 at 07:00, Leslie Zhai via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Testcase: <a href="https://github.com/xiangzhai/mini-arm-os/tree/llvm-toolchain/00-HelloWorld" rel="noreferrer" target="_blank">https://github.com/xiangzhai/m<wbr>ini-arm-os/tree/llvm-toolchain<wbr>/00-HelloWorld</a><br>
<br>
$ make<br>
CC hello.c<br>
CC startup.c<br>
LD hello.elf<br>
READ -> hello.rd<br>
LIST -> hello.lst<br>
COPY -> hello.bin<br>
text data bss dec hex filename<br>
190 14 0 204 cc hello.elf<br>
<br>
$ make qemu<br>
/data/project/qemu_stm32/arm-s<wbr>oftmmu/qemu-system-arm -M stm32-p103 -nographic -kernel hello.bin<br>
<br>
...<br>
LED Off<br>
Hello World!<br>
<br>
<br>
在 2017年11月13日 14:14, Leslie Zhai 写道:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is it able to just workaround add ELF32LE?<br>
<br>
<br>
diff --git a/tools/llvm-objcopy/llvm-objc<wbr>opy.cpp b/tools/llvm-objcopy/llvm-objc<wbr>opy.cpp<br>
index 54186f6..3234c65 100644<br>
--- a/tools/llvm-objcopy/llvm-objc<wbr>opy.cpp<br>
+++ b/tools/llvm-objcopy/llvm-objc<wbr>opy.cpp<br>
@@ -138,18 +138,19 @@ void SplitDWOToFile(const ELFObjectFile<ELFT> &ObjFile, StringRef File) {<br>
WriteObjectFile(DWOFile, File);<br>
}<br>
<br>
-void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {<br>
- std::unique_ptr<Object<ELF64LE<wbr>>> Obj;<br>
+template <class ELFT = ELF64LE><br>
+void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) {<br>
+ std::unique_ptr<Object<ELFT>> Obj;<br>
<br>
if (!OutputFormat.empty() && OutputFormat != "binary")<br>
error("invalid output format '" + OutputFormat + "'");<br>
if (!OutputFormat.empty() && OutputFormat == "binary")<br>
- Obj = llvm::make_unique<BinaryObject<wbr><ELF64LE>>(ObjFile);<br>
+ Obj = llvm::make_unique<BinaryObject<wbr><ELFT>>(ObjFile);<br>
else<br>
- Obj = llvm::make_unique<ELFObject<EL<wbr>F64LE>>(ObjFile);<br>
+ Obj = llvm::make_unique<ELFObject<EL<wbr>FT>>(ObjFile);<br>
<br>
if (!SplitDWO.empty())<br>
- SplitDWOToFile<ELF64LE>(ObjFil<wbr>e, SplitDWO.getValue());<br>
+ SplitDWOToFile<ELFT>(ObjFile, SplitDWO.getValue());<br>
<br>
SectionPred RemovePred = [](const SectionBase &) { return false; };<br>
<br>
@@ -200,6 +201,9 @@ int main(int argc, char **argv) {<br>
if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE<wbr>>>(&Binary)) {<br>
CopyBinary(*o);<br>
return 0;<br>
+ } else if (ELFObjectFile<ELF32LE> *o = dyn_cast<ELFObjectFile<ELF32LE<wbr>>>(&Binary)) {<br>
+ CopyBinary(*o);<br>
+ return 0;<br>
}<br>
reportError(InputFilename, object_error::invalid_file_typ<wbr>e);<br>
}<br>
<br>
<br>
<br>
在 2017年11月13日 11:32, Leslie Zhai 写道:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi LLVM developers,<br>
<br>
As PR35281 mentioned:<br>
<br>
$ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin<br>
llvm-objcopy: 'llvm-cortex-m7.elf': The file was not recognized as a valid object file.<br>
<br>
<br>
if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE<wbr>>>(&Binary)) <a href="https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200" rel="noreferrer" target="_blank">https://github.com/llvm-mirror<wbr>/llvm/blob/master/tools/llvm-<wbr>objcopy/llvm-objcopy.cpp#L200</a><br>
<br>
<br>
Please give me some hints about objcopy armv7e-m ELF32LE via LLVM toolchain, thanks a lot!<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
-- <br>
Regards,<br>
Leslie Zhai - <a href="https://reviews.llvm.org/p/xiangzhai/" rel="noreferrer" target="_blank">https://reviews.llvm.org/p/xia<wbr>ngzhai/</a><br>
<br></div></div><div class="HOEnZb"><div class="h5">
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>