[ELF] Accept first SHT_ARM_ATTRIBUTES section
    
The eglibc library, as used by Ubuntu 14.04 requires the presence of an
SHT_ARM_ATTRIBUTES section in for the purposes of checking hard/soft float
compatibility when dlopen() is used. Unfortunately when the section is not
present dlopen() fails with a generic could not find file message.
    
This change makes lld keep the first .ARM.attributes section that it
encounters and propagates it to the output. This is not a complete
SHT_ARM_ATTRIBUTES implementation, that would involve reading the contents
of the section and joining each individual attribute. It should suffice
for a homogenous build all libraries and executables on the same system
with a compatible set of command line options.

Differential revision: https://reviews.llvm.org/D27718

llvm-svn: 289642
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 37ebfa7..b7f1aea 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -14,6 +14,7 @@
 #include "LinkerScript.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
+#include "SyntheticSections.h"
 #include "lld/Support/Memory.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -336,8 +337,14 @@
 
   switch (Sec.sh_type) {
   case SHT_ARM_ATTRIBUTES:
-    // FIXME: ARM meta-data section. At present attributes are ignored,
-    // they can be used to reason about object compatibility.
+    // FIXME: ARM meta-data section. Retain the first attribute section
+    // we see. The eglibc ARM dynamic loaders require the presence of an
+    // attribute section for dlopen to work.
+    // In a full implementation we would merge all attribute sections.
+    if (In<ELFT>::ARMAttributes == nullptr) {
+      In<ELFT>::ARMAttributes = make<InputSection<ELFT>>(this, &Sec, Name);
+      return In<ELFT>::ARMAttributes;
+    }
     return &InputSection<ELFT>::Discarded;
   case SHT_RELA:
   case SHT_REL: {