[llvm-dev] How to objcopy via LLVM toolchain for armv7e-m ELF32LE? (original) (raw)

Leslie Zhai via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 12 23:00:58 PST 2017


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 > &ObjFile, StringRef File) { > WriteObjectFile(DWOFile, File);} >> -void CopyBinary(const ELFObjectFile &ObjFile) { > -  std::uniqueptr<Object> Obj; > +template > +void CopyBinary(const ELFObjectFile &ObjFile) { > +  std::uniqueptr<Object> Obj; >> if (!OutputFormat.empty() && OutputFormat != "binary") > error("invalid output format '" + OutputFormat + "'"); > if (!OutputFormat.empty() && OutputFormat == "binary") > -    Obj = llvm::makeunique<BinaryObject>(ObjFile); > +    Obj = llvm::makeunique<BinaryObject>(ObjFile); > else > -    Obj = llvm::makeunique<ELFObject>(ObjFile); > +    Obj = llvm::makeunique<ELFObject>(ObjFile); >> if (!SplitDWO.empty()) > -    SplitDWOToFile(ObjFile, SplitDWO.getValue()); > +    SplitDWOToFile(ObjFile, SplitDWO.getValue()); >> SectionPred RemovePred = [](const SectionBase &) { return false; }; >> @@ -200,6 +201,9 @@ int main(int argc, char **argv) { > if (ELFObjectFile *o = > dyncast<ELFObjectFile>(&Binary)) { > CopyBinary(*o); > return 0; > +  } else if (ELFObjectFile *o = > dyncast<ELFObjectFile>(&Binary)) { > +    CopyBinary(*o); > +    return 0; > } > reportError(InputFilename, objecterror::invalidfiletype);} >>>> 在 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 *o = >> dyncast<ELFObjectFile>(&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/



More information about the llvm-dev mailing list