X-Git-Url: http://drtracing.org/?a=blobdiff_plain;ds=sidebyside;f=gold%2Fbinary.cc;h=c68524669a4c5fbb2af3a605500557c7f2368bf2;hb=c9debfb97e052c32cf0308157cae529ce2059f48;hp=9909ff4e8ed562e957f4548522f711f88a1e9d36;hpb=bc644c6cfca852cd34e486a018bfde7fd1ac55e8;p=deliverable%2Fbinutils-gdb.git diff --git a/gold/binary.cc b/gold/binary.cc index 9909ff4e8e..c68524669a 100644 --- a/gold/binary.cc +++ b/gold/binary.cc @@ -1,6 +1,6 @@ // binary.cc -- binary input files for gold -// Copyright 2008 Free Software Foundation, Inc. +// Copyright (C) 2008-2020 Free Software Foundation, Inc. // Written by Ian Lance Taylor . // This file is part of gold. @@ -24,7 +24,6 @@ #include #include -#include "safe-ctype.h" #include "elfcpp.h" #include "stringpool.h" @@ -32,10 +31,17 @@ #include "output.h" #include "binary.h" +// safe-ctype.h interferes with macros defined by the system . +// Some C++ system headers might include and rely on its macro +// definitions being intact. So make sure that safe-ctype.h is included +// only after any C++ system headers, whether directly here (above) or via +// other local header files (e.g. #include in "binary.h"). +#include "safe-ctype.h" + // Support for reading binary files as input. These become blobs in // the final output. These files are treated as though they have a // single .data section and define three symbols: -// _binary_FILENAME_start, _binary_FILENAME_end, _binary_FILENAME_end. +// _binary_FILENAME_start, _binary_FILENAME_end, _binary_FILENAME_size. // The FILENAME is the name of the input file, with any // non-alphanumeric character changed to an underscore. @@ -132,7 +138,11 @@ Binary_to_elf::sized_convert(const Task* task) } section_size_type filesize = convert_to_section_size_type(f.filesize()); - const unsigned char* fileview = f.get_view(0, filesize, false); + const unsigned char* fileview; + if (filesize == 0) + fileview = NULL; + else + fileview = f.get_view(0, 0, filesize, false, false); unsigned int align; if (size == 32) @@ -198,16 +208,16 @@ Binary_to_elf::sized_convert(const Task* task) this->write_section_header("", &shstrtab, elfcpp::SHT_NULL, 0, 0, 0, 0, 0, 0, 0, &pout); - // Having the section be named ".data" and having it be writable is - // because th GNU linker does it that way, and existing linker - // script expect it. + // Having the section be named ".data", having it be writable, and + // giving it an alignment of 1 is because the GNU linker does it + // that way, and existing linker script expect it. this->write_section_header(".data", &shstrtab, elfcpp::SHT_PROGBITS, (elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE), data_offset, filesize, 0, 0, - align, 0, &pout); + 1, 0, &pout); this->write_section_header(".symtab", &shstrtab, elfcpp::SHT_SYMTAB, 0, symtab_offset, 4 * sym_size, @@ -223,17 +233,20 @@ Binary_to_elf::sized_convert(const Task* task) shstrtab.get_strtab_size(), 0, 0, 1, 0, &pout); - memcpy(pout, fileview, filesize); - pout += filesize; - memset(pout, 0, aligned_filesize - filesize); - pout += aligned_filesize - filesize; - - this->write_symbol("", &strtab, 0, 0, &pout); - this->write_symbol(start_symbol_name, &strtab, 0, 1, - &pout); - this->write_symbol(end_symbol_name, &strtab, filesize, 1, - &pout); - this->write_symbol(size_symbol_name, &strtab, filesize, + if (filesize > 0) + { + memcpy(pout, fileview, filesize); + pout += filesize; + memset(pout, 0, aligned_filesize - filesize); + pout += aligned_filesize - filesize; + } + + this->write_symbol("", &strtab, 0, 0, 0, &pout); + this->write_symbol(start_symbol_name, &strtab, 0, filesize, + 1, &pout); + this->write_symbol(end_symbol_name, &strtab, filesize, 0, + 1, &pout); + this->write_symbol(size_symbol_name, &strtab, filesize, 0, elfcpp::SHN_ABS, &pout); strtab.write_to_buffer(pout, strtab.get_strtab_size()); @@ -336,6 +349,7 @@ Binary_to_elf::write_symbol( const std::string& name, const Stringpool* strtab, section_size_type value, + typename elfcpp::Elf_types<32>::Elf_WXword st_size, unsigned int shndx, unsigned char** ppout) { @@ -344,7 +358,7 @@ Binary_to_elf::write_symbol( elfcpp::Sym_write osym(pout); osym.put_st_name(name.empty() ? 0 : strtab->get_offset(name.c_str())); osym.put_st_value(value); - osym.put_st_size(0); + osym.put_st_size(st_size); osym.put_st_info(name.empty() ? elfcpp::STB_LOCAL : elfcpp::STB_GLOBAL, elfcpp::STT_NOTYPE); osym.put_st_other(elfcpp::STV_DEFAULT, 0);