Leslie Zhai via llvm-dev
2017-Nov-13 03:32 UTC
[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE?
Hi LLVM developers, As PR35281 mentioned: $ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin llvm-objcopy: 'llvm-cortex-m7.elf': The file was not recognized as a valid object file. if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200 Please give me some hints about objcopy armv7e-m ELF32LE via LLVM toolchain, thanks a lot! -- Regards, Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/
Leslie Zhai via llvm-dev
2017-Nov-13 06:14 UTC
[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE?
Is it able to just workaround add ELF32LE? diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp b/tools/llvm-objcopy/llvm-objcopy.cpp index 54186f6..3234c65 100644 --- a/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/tools/llvm-objcopy/llvm-objcopy.cpp @@ -138,18 +138,19 @@ void SplitDWOToFile(const ELFObjectFile<ELFT> &ObjFile, StringRef File) { WriteObjectFile(DWOFile, File); } -void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) { - std::unique_ptr<Object<ELF64LE>> Obj; +template <class ELFT = ELF64LE> +void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) { + std::unique_ptr<Object<ELFT>> Obj; if (!OutputFormat.empty() && OutputFormat != "binary") error("invalid output format '" + OutputFormat + "'"); if (!OutputFormat.empty() && OutputFormat == "binary") - Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile); + Obj = llvm::make_unique<BinaryObject<ELFT>>(ObjFile); else - Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile); + Obj = llvm::make_unique<ELFObject<ELFT>>(ObjFile); if (!SplitDWO.empty()) - SplitDWOToFile<ELF64LE>(ObjFile, SplitDWO.getValue()); + SplitDWOToFile<ELFT>(ObjFile, SplitDWO.getValue()); SectionPred RemovePred = [](const SectionBase &) { return false; }; @@ -200,6 +201,9 @@ int main(int argc, char **argv) { if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) { CopyBinary(*o); return 0; + } else if (ELFObjectFile<ELF32LE> *o = dyn_cast<ELFObjectFile<ELF32LE>>(&Binary)) { + CopyBinary(*o); + return 0; } reportError(InputFilename, object_error::invalid_file_type); } 在 2017年11月13日 11:32, Leslie Zhai 写道:> Hi LLVM developers, > > As PR35281 mentioned: > > $ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin > llvm-objcopy: 'llvm-cortex-m7.elf': The file was not recognized as a > valid object file. > > > if (ELFObjectFile<ELF64LE> *o = > dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) > https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200 > > > Please give me some hints about objcopy armv7e-m ELF32LE via LLVM > toolchain, thanks a lot! >-- Regards, Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/
Leslie Zhai via llvm-dev
2017-Nov-13 07:00 UTC
[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE?
Testcase: https://github.com/xiangzhai/mini-arm-os/tree/llvm-toolchain/00-HelloWorld $ make CC hello.c CC startup.c LD hello.elf READ -> hello.rd LIST -> hello.lst COPY -> hello.bin text data bss dec hex filename 190 14 0 204 cc hello.elf $ make qemu /data/project/qemu_stm32/arm-softmmu/qemu-system-arm -M stm32-p103 -nographic -kernel hello.bin ... LED Off Hello World! 在 2017年11月13日 14:14, Leslie Zhai 写道:> Is it able to just workaround add ELF32LE? > > > diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp > b/tools/llvm-objcopy/llvm-objcopy.cpp > index 54186f6..3234c65 100644 > --- a/tools/llvm-objcopy/llvm-objcopy.cpp > +++ b/tools/llvm-objcopy/llvm-objcopy.cpp > @@ -138,18 +138,19 @@ void SplitDWOToFile(const ELFObjectFile<ELFT> > &ObjFile, StringRef File) { > WriteObjectFile(DWOFile, File); > } > > -void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) { > - std::unique_ptr<Object<ELF64LE>> Obj; > +template <class ELFT = ELF64LE> > +void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) { > + std::unique_ptr<Object<ELFT>> Obj; > > if (!OutputFormat.empty() && OutputFormat != "binary") > error("invalid output format '" + OutputFormat + "'"); > if (!OutputFormat.empty() && OutputFormat == "binary") > - Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile); > + Obj = llvm::make_unique<BinaryObject<ELFT>>(ObjFile); > else > - Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile); > + Obj = llvm::make_unique<ELFObject<ELFT>>(ObjFile); > > if (!SplitDWO.empty()) > - SplitDWOToFile<ELF64LE>(ObjFile, SplitDWO.getValue()); > + SplitDWOToFile<ELFT>(ObjFile, SplitDWO.getValue()); > > SectionPred RemovePred = [](const SectionBase &) { return false; }; > > @@ -200,6 +201,9 @@ int main(int argc, char **argv) { > if (ELFObjectFile<ELF64LE> *o = > dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) { > CopyBinary(*o); > return 0; > + } else if (ELFObjectFile<ELF32LE> *o = > dyn_cast<ELFObjectFile<ELF32LE>>(&Binary)) { > + CopyBinary(*o); > + return 0; > } > reportError(InputFilename, object_error::invalid_file_type); > } > > > > 在 2017年11月13日 11:32, Leslie Zhai 写道: >> Hi LLVM developers, >> >> As PR35281 mentioned: >> >> $ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin >> llvm-objcopy: 'llvm-cortex-m7.elf': The file was not recognized as a >> valid object file. >> >> >> if (ELFObjectFile<ELF64LE> *o = >> dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) >> https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200 >> >> >> Please give me some hints about objcopy armv7e-m ELF32LE via LLVM >> toolchain, thanks a lot! >> >-- Regards, Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/
James Henderson via llvm-dev
2017-Nov-13 14:27 UTC
[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE?
Hi, 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. Regards, James On 13 November 2017 at 07:00, Leslie Zhai via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Testcase: https://github.com/xiangzhai/mini-arm-os/tree/llvm-toolchain > /00-HelloWorld > > $ make > CC hello.c > CC startup.c > LD hello.elf > READ -> hello.rd > LIST -> hello.lst > COPY -> hello.bin > text data bss dec hex filename > 190 14 0 204 cc hello.elf > > $ make qemu > /data/project/qemu_stm32/arm-softmmu/qemu-system-arm -M stm32-p103 > -nographic -kernel hello.bin > > ... > LED Off > Hello World! > > > 在 2017年11月13日 14:14, Leslie Zhai 写道: > >> Is it able to just workaround add ELF32LE? >> >> >> diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp >> b/tools/llvm-objcopy/llvm-objcopy.cpp >> index 54186f6..3234c65 100644 >> --- a/tools/llvm-objcopy/llvm-objcopy.cpp >> +++ b/tools/llvm-objcopy/llvm-objcopy.cpp >> @@ -138,18 +138,19 @@ void SplitDWOToFile(const ELFObjectFile<ELFT> >> &ObjFile, StringRef File) { >> WriteObjectFile(DWOFile, File); >> } >> >> -void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) { >> - std::unique_ptr<Object<ELF64LE>> Obj; >> +template <class ELFT = ELF64LE> >> +void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) { >> + std::unique_ptr<Object<ELFT>> Obj; >> >> if (!OutputFormat.empty() && OutputFormat != "binary") >> error("invalid output format '" + OutputFormat + "'"); >> if (!OutputFormat.empty() && OutputFormat == "binary") >> - Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile); >> + Obj = llvm::make_unique<BinaryObject<ELFT>>(ObjFile); >> else >> - Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile); >> + Obj = llvm::make_unique<ELFObject<ELFT>>(ObjFile); >> >> if (!SplitDWO.empty()) >> - SplitDWOToFile<ELF64LE>(ObjFile, SplitDWO.getValue()); >> + SplitDWOToFile<ELFT>(ObjFile, SplitDWO.getValue()); >> >> SectionPred RemovePred = [](const SectionBase &) { return false; }; >> >> @@ -200,6 +201,9 @@ int main(int argc, char **argv) { >> if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) >> { >> CopyBinary(*o); >> return 0; >> + } else if (ELFObjectFile<ELF32LE> *o = dyn_cast<ELFObjectFile<ELF32LE>>(&Binary)) >> { >> + CopyBinary(*o); >> + return 0; >> } >> reportError(InputFilename, object_error::invalid_file_type); >> } >> >> >> >> 在 2017年11月13日 11:32, Leslie Zhai 写道: >> >>> Hi LLVM developers, >>> >>> As PR35281 mentioned: >>> >>> $ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin >>> llvm-objcopy: 'llvm-cortex-m7.elf': The file was not recognized as a >>> valid object file. >>> >>> >>> if (ELFObjectFile<ELF64LE> *o = dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) >>> https://github.com/llvm-mirror/llvm/blob/master/tools/llvm- >>> objcopy/llvm-objcopy.cpp#L200 >>> >>> >>> Please give me some hints about objcopy armv7e-m ELF32LE via LLVM >>> toolchain, thanks a lot! >>> >>> >> > -- > Regards, > Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/ > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171113/615e4ab1/attachment.html>
Leslie Zhai via llvm-dev
2017-Nov-14 02:07 UTC
[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE?
Hi James, Thanks for your kind response! Jake has already provided the great patch https://reviews.llvm.org/D39977 The Flash Man :) so quick response to cover ARMmbed usecase for armv7e-m! Thanks again for your great job! 在 2017年11月13日 22:27, James Henderson 写道:> Hi, > > 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. > > Regards, > > James > > On 13 November 2017 at 07:00, Leslie Zhai via llvm-dev > <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > > Testcase: > https://github.com/xiangzhai/mini-arm-os/tree/llvm-toolchain/00-HelloWorld > <https://github.com/xiangzhai/mini-arm-os/tree/llvm-toolchain/00-HelloWorld> > > $ make > CC hello.c > CC startup.c > LD hello.elf > READ -> hello.rd > LIST -> hello.lst > COPY -> hello.bin > text data bss dec hex filename > 190 14 0 204 cc hello.elf > > $ make qemu > /data/project/qemu_stm32/arm-softmmu/qemu-system-arm -M stm32-p103 > -nographic -kernel hello.bin > > ... > LED Off > Hello World! > > > 在 2017年11月13日 14:14, Leslie Zhai 写道: > > Is it able to just workaround add ELF32LE? > > > diff --git a/tools/llvm-objcopy/llvm-objcopy.cpp > b/tools/llvm-objcopy/llvm-objcopy.cpp > index 54186f6..3234c65 100644 > --- a/tools/llvm-objcopy/llvm-objcopy.cpp > +++ b/tools/llvm-objcopy/llvm-objcopy.cpp > @@ -138,18 +138,19 @@ void SplitDWOToFile(const > ELFObjectFile<ELFT> &ObjFile, StringRef File) { > WriteObjectFile(DWOFile, File); > } > > -void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) { > - std::unique_ptr<Object<ELF64LE>> Obj; > +template <class ELFT = ELF64LE> > +void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) { > + std::unique_ptr<Object<ELFT>> Obj; > > if (!OutputFormat.empty() && OutputFormat != "binary") > error("invalid output format '" + OutputFormat + "'"); > if (!OutputFormat.empty() && OutputFormat == "binary") > - Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile); > + Obj = llvm::make_unique<BinaryObject<ELFT>>(ObjFile); > else > - Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile); > + Obj = llvm::make_unique<ELFObject<ELFT>>(ObjFile); > > if (!SplitDWO.empty()) > - SplitDWOToFile<ELF64LE>(ObjFile, SplitDWO.getValue()); > + SplitDWOToFile<ELFT>(ObjFile, SplitDWO.getValue()); > > SectionPred RemovePred = [](const SectionBase &) { return > false; }; > > @@ -200,6 +201,9 @@ int main(int argc, char **argv) { > if (ELFObjectFile<ELF64LE> *o > dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) { > CopyBinary(*o); > return 0; > + } else if (ELFObjectFile<ELF32LE> *o > dyn_cast<ELFObjectFile<ELF32LE>>(&Binary)) { > + CopyBinary(*o); > + return 0; > } > reportError(InputFilename, object_error::invalid_file_type); > } > > > > 在 2017年11月13日 11:32, Leslie Zhai 写道: > > Hi LLVM developers, > > As PR35281 mentioned: > > $ llvm-objcopy -O binary llvm-cortex-m7.elf llvm-cortex-m7.bin > llvm-objcopy: 'llvm-cortex-m7.elf': The file was not > recognized as a valid object file. > > > if (ELFObjectFile<ELF64LE> *o > dyn_cast<ELFObjectFile<ELF64LE>>(&Binary)) > https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200 > <https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/llvm-objcopy.cpp#L200> > > > Please give me some hints about objcopy armv7e-m ELF32LE > via LLVM toolchain, thanks a lot! > > > > -- > Regards, > Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/ > <https://reviews.llvm.org/p/xiangzhai/> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > >-- Regards, Leslie Zhai - https://reviews.llvm.org/p/xiangzhai/