@@ -71,14 +71,32 @@ InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags,
71
71
this ->Alignment = V;
72
72
}
73
73
74
+ // GNU assembler 2.24 and LLVM 4.0.0's MC (the newest release as of
75
+ // March 2017) fail to infer section types for sections starting with
76
+ // ".init_array." or ".fini_array.". They set SHT_PROGBITS instead of
77
+ // SHF_INIT_ARRAY. As a result, the following assembler directive
78
+ // creates ".init_array.100" with SHT_PROGBITS, for example.
79
+ //
80
+ // .section .init_array.100, "aw"
81
+ //
82
+ // This function forces SHT_{INIT,FINI}_ARRAY so that we can handle
83
+ // incorrect inputs as if they were correct from the beginning.
84
+ static uint64_t getType (uint64_t Type, StringRef Name) {
85
+ if (Type == SHT_PROGBITS && Name.startswith (" .init_array." ))
86
+ return SHT_INIT_ARRAY;
87
+ if (Type == SHT_PROGBITS && Name.startswith (" .fini_array." ))
88
+ return SHT_FINI_ARRAY;
89
+ return Type;
90
+ }
91
+
74
92
template <class ELFT >
75
93
InputSectionBase::InputSectionBase (elf::ObjectFile<ELFT> *File,
76
94
const typename ELFT::Shdr *Hdr,
77
95
StringRef Name, Kind SectionKind)
78
- : InputSectionBase(File, Hdr->sh_flags & ~SHF_INFO_LINK, Hdr->sh_type,
79
- Hdr->sh_entsize, Hdr->sh_link , Hdr->sh_info ,
80
- Hdr->sh_addralign, getSectionContents(File, Hdr), Name ,
81
- SectionKind) {
96
+ : InputSectionBase(File, Hdr->sh_flags & ~SHF_INFO_LINK,
97
+ getType ( Hdr->sh_type, Name) , Hdr->sh_entsize ,
98
+ Hdr->sh_link, Hdr->sh_info, Hdr->sh_addralign ,
99
+ getSectionContents(File, Hdr), Name, SectionKind) {
82
100
// We reject object files having insanely large alignments even though
83
101
// they are allowed by the spec. I think 4GB is a reasonable limitation.
84
102
// We might want to relax this in the future.
0 commit comments