MCPcopy Create free account
hub / github.com/Kitware/CMake / cmELF

Method cmELF

Source/cmELF.cxx:667–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

665long const cmELF::TagMipsRldMapRel = DT_MIPS_RLD_MAP_REL;
666
667cmELF::cmELF(char const* fname)
668{
669 // Try to open the file.
670 auto fin = cm::make_unique<cmsys::ifstream>(fname, std::ios::binary);
671
672 // Quit now if the file could not be opened.
673 if (!fin || !*fin) {
674 this->ErrorMessage = "Error opening input file.";
675 return;
676 }
677
678 // Read the ELF identification block.
679 char ident[EI_NIDENT];
680 if (!fin->read(ident, EI_NIDENT)) {
681 this->ErrorMessage = "Error reading ELF identification.";
682 return;
683 }
684 if (!fin->seekg(0)) {
685 this->ErrorMessage = "Error seeking to beginning of file.";
686 return;
687 }
688
689 // Verify the ELF identification.
690 if (!(ident[EI_MAG0] == ELFMAG0 && ident[EI_MAG1] == ELFMAG1 &&
691 ident[EI_MAG2] == ELFMAG2 && ident[EI_MAG3] == ELFMAG3)) {
692 this->ErrorMessage = "File does not have a valid ELF identification.";
693 return;
694 }
695
696 // Check the byte order in which the rest of the file is encoded.
697 cmELFInternal::ByteOrderType order;
698 if (ident[EI_DATA] == ELFDATA2LSB) {
699 // File is LSB.
700 order = cmELFInternal::ByteOrderLSB;
701 } else if (ident[EI_DATA] == ELFDATA2MSB) {
702 // File is MSB.
703 order = cmELFInternal::ByteOrderMSB;
704 } else {
705 this->ErrorMessage = "ELF file is not LSB or MSB encoded.";
706 return;
707 }
708
709 // Check the class of the file and construct the corresponding
710 // parser implementation.
711 if (ident[EI_CLASS] == ELFCLASS32) {
712 // 32-bit ELF
713 this->Internal = cm::make_unique<cmELFInternalImpl<cmELFTypes32>>(
714 this, std::move(fin), order);
715 } else if (ident[EI_CLASS] == ELFCLASS64) {
716 // 64-bit ELF
717 this->Internal = cm::make_unique<cmELFInternalImpl<cmELFTypes64>>(
718 this, std::move(fin), order);
719 } else {
720 this->ErrorMessage = "ELF file class is not 32-bit or 64-bit.";
721 return;
722 }
723}
724

Callers

nothing calls this directly

Calls 2

moveFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected