Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[linux-drm-fsl-dcu.git] / scripts / sortextable.c
index 7c2310c5b996dee9d43df56574b30236342c3c81..5f7a8b663cb9c9eb59b32f4ce63076a6a86914cc 100644 (file)
@@ -152,6 +152,30 @@ static void (*w2)(uint16_t, uint16_t *);
 
 typedef void (*table_sort_t)(char *, int);
 
+/*
+ * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
+ * the way to -256..-1, to avoid conflicting with real section
+ * indices.
+ */
+#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
+
+static inline int is_shndx_special(unsigned int i)
+{
+       return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
+}
+
+/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
+static inline unsigned int get_secindex(unsigned int shndx,
+                                       unsigned int sym_offs,
+                                       const Elf32_Word *symtab_shndx_start)
+{
+       if (is_shndx_special(shndx))
+               return SPECIAL(shndx);
+       if (shndx != SHN_XINDEX)
+               return shndx;
+       return r(&symtab_shndx_start[sym_offs]);
+}
+
 /* 32 bit and 64 bit are very similar */
 #include "sortextable.h"
 #define SORTEXTABLE_64