diff --git a/input_files.cc b/input_files.cc index c303b855..4e30a782 100644 --- a/input_files.cc +++ b/input_files.cc @@ -75,6 +75,8 @@ void ObjectFile::initialize_sections() { default: { StringRef name = CHECK(obj.getSectionName(shdr, section_strtab), this); this->sections[i] = new InputSection(this, &shdr, name); + if (name == ".init_array" && (shdr.sh_type & SHT_NOBITS)) + llvm::outs() << toString(this) << "\n"; break; } } diff --git a/main.cc b/main.cc index 467fce01..dbb91e1c 100644 --- a/main.cc +++ b/main.cc @@ -101,26 +101,25 @@ static void read_file(std::vector &files, StringRef path) { } } +thread_local int foo; +thread_local int bar = 5; + // We want to sort output sections in the following order. // -// alloc !writable !exec !tls !nobits -// alloc !writable !exec !tls nobits -// alloc !writable !exec tls !nobits -// alloc !writable !exec tls nobits -// alloc !writable exec -// alloc writable !exec !tls !nobits -// alloc writable !exec !tls nobits -// alloc writable !exec tls !nobits -// alloc writable !exec tls nobits -// alloc writable exec -// !alloc +// alloc readonly data +// alloc readonly code +// alloc writable tdata +// alloc writable tbss +// alloc writable data +// alloc writable bss +// nonalloc static int get_rank(OutputSection *x) { bool alloc = x->hdr.sh_flags & SHF_ALLOC; bool writable = x->hdr.sh_flags & SHF_WRITE; bool exec = x->hdr.sh_flags & SHF_EXECINSTR; bool tls = x->hdr.sh_flags & SHF_TLS; bool nobits = x->hdr.sh_type & SHT_NOBITS; - return (alloc << 5) | (!writable << 4) | (!exec << 3) | (!tls << 2) | !nobits; + return (alloc << 5) | (!writable << 4) | (!exec << 3) | (tls << 2) | !nobits; } static std::vector get_output_sections() { @@ -129,6 +128,9 @@ static std::vector get_output_sections() { if (!osec->chunks.empty()) vec.push_back(osec); + for (OutputSection *osec : vec) + llvm::outs() << osec->name << ": " << get_rank(osec) << "\n"; + std::sort(vec.begin(), vec.end(), [](OutputSection *a, OutputSection *b) { int x = get_rank(a); int y = get_rank(b);