recordmcount: Fix handling of elf64 big-endian objects.
[pandora-kernel.git] / scripts / recordmcount.h
index 4be6036..54e35c1 100644 (file)
@@ -43,6 +43,7 @@
 #undef ELF_R_INFO
 #undef Elf_r_info
 #undef ELF_ST_BIND
+#undef ELF_ST_TYPE
 #undef fn_ELF_R_SYM
 #undef fn_ELF_R_INFO
 #undef uint_t
@@ -76,6 +77,7 @@
 # define ELF_R_INFO            ELF64_R_INFO
 # define Elf_r_info            Elf64_r_info
 # define ELF_ST_BIND           ELF64_ST_BIND
+# define ELF_ST_TYPE           ELF64_ST_TYPE
 # define fn_ELF_R_SYM          fn_ELF64_R_SYM
 # define fn_ELF_R_INFO         fn_ELF64_R_INFO
 # define uint_t                        uint64_t
 # define ELF_R_INFO            ELF32_R_INFO
 # define Elf_r_info            Elf32_r_info
 # define ELF_ST_BIND           ELF32_ST_BIND
+# define ELF_ST_TYPE           ELF32_ST_TYPE
 # define fn_ELF_R_SYM          fn_ELF32_R_SYM
 # define fn_ELF_R_INFO         fn_ELF32_R_INFO
 # define uint_t                        uint32_t
@@ -427,6 +430,11 @@ static unsigned find_secsym_ndx(unsigned const txtndx,
                if (txtndx == w2(symp->st_shndx)
                        /* avoid STB_WEAK */
                    && (STB_LOCAL == st_bind || STB_GLOBAL == st_bind)) {
+                       /* function symbols on ARM have quirks, avoid them */
+                       if (w2(ehdr->e_machine) == EM_ARM
+                           && ELF_ST_TYPE(symp->st_info) == STT_FUNC)
+                               continue;
+
                        *recvalp = _w(symp->st_value);
                        return symp - sym0;
                }
@@ -454,7 +462,7 @@ __has_rel_mcount(Elf_Shdr const *const relhdr,  /* is SHT_REL or SHT_RELA */
                succeed_file();
        }
        if (w(txthdr->sh_type) != SHT_PROGBITS ||
-           !(w(txthdr->sh_flags) & SHF_EXECINSTR))
+           !(_w(txthdr->sh_flags) & SHF_EXECINSTR))
                return NULL;
        return txtname;
 }