1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 10:54:56 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-20 00:08:07 +09:00
parent 0c2e3e30be
commit 86781e9b64
3 changed files with 10 additions and 9 deletions

View File

@ -173,15 +173,12 @@ public:
void copy_to(uint8_t *buf); void copy_to(uint8_t *buf);
uint64_t get_size() const; uint64_t get_size() const;
uint64_t get_alignment() const {
return (hdr->sh_addralign == 0) ? 1 : hdr->sh_addralign;
}
ObjectFile *file; ObjectFile *file;
OutputSection *output_section; OutputSection *output_section;
StringRef output_section_name; StringRef output_section_name;
uint64_t output_file_offset; uint64_t output_file_offset;
int64_t offset = -1; int64_t offset = -1;
uint32_t alignment;
private: private:
const ELF64LE::Shdr *hdr; const ELF64LE::Shdr *hdr;

View File

@ -24,8 +24,12 @@ InputSection::InputSection(ObjectFile *file, const ELF64LE::Shdr *hdr, StringRef
this->name = name; this->name = name;
this->output_section = get_output_section(name); this->output_section = get_output_section(name);
if (hdr->sh_addralign > UINT32_MAX) uint64_t align = (hdr->sh_addralign == 0) ? 1 : hdr->sh_addralign;
if (align > UINT32_MAX)
error(toString(file) + ": section sh_addralign is too large"); error(toString(file) + ": section sh_addralign is too large");
if (__builtin_popcount(align) != 1)
error(toString(file) + ": section sh_addralign is not a power of two");
this->alignment = align;
} }
uint64_t InputSection::get_size() const { uint64_t InputSection::get_size() const {

View File

@ -178,7 +178,7 @@ int main(int argc, char **argv) {
uint64_t off = 0; uint64_t off = 0;
for (OutputSection *osec : output_sections) { for (OutputSection *osec : output_sections) {
for (InputSection *isec : osec->sections) { for (InputSection *isec : osec->sections) {
off = align_to(off, isec->get_alignment()); off = align_to(off, isec->alignment);
isec->output_file_offset = off; isec->output_file_offset = off;
off += isec->get_size(); off += isec->get_size();
} }
@ -189,9 +189,9 @@ int main(int argc, char **argv) {
int max_align = 0; int max_align = 0;
for (OutputSection *osec : output_sections) { for (OutputSection *osec : output_sections) {
for (InputSection *isec : osec->sections) { for (InputSection *isec : osec->sections) {
if (isec->get_alignment() > max_align) { if (isec->alignment > max_align) {
llvm::outs() << toString(isec) << " " << isec->get_alignment() << "\n"; llvm::outs() << toString(isec) << " " << isec->alignment << "\n";
max_align = isec->get_alignment(); max_align = isec->alignment;
} }
} }
} }