This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/4] Nios II: elf subdir changes, unsigned divide in ld.so


This patch contains the changes in the elf/ subdir. The main changes are:

(1) The changes to add Nios II to elf/elf.h, machine number,
relocations, etc. Pretty standard stuff copied from BFD.

(2) A change in elf/dynamic-link.h, to allow a port to define a special
unsigned integer divide during RTLD_BOOTSTRAP, by defining
RTLD_BOOTSTRAP_UDIV.

The rationale is: while Nios II does have optional hardware integer
divide defined as part of the ISA spec, the current support we're
working on here is for the common no-divider case, relying on libgcc
__udivsi3.

Unfortunately however, Nios II does not have PC-relative calls (only a
direct transfer call similar to MIPS), so all subroutine calls under PIC
have to go through the GOT, which... is not available yet during
RTLD_BOOTSTRAP.

So the RTLD_BOOTSTRAP_UDIV macro facility allows nios2 to define its own
inline udiv in dl-machine.h, for use when libgcc is still not accessible.

Thanks,
Chung-Lin

        * elf/dynamic-link.h (RTLD_UDIV): New macro.
        (elf_machine_lazy_rel): Change divide operation to use RTLD_UDIV.
        * elf/elf.h (EM_ALTERA_NIOS2): New machine number for Altera
Nios II.
        (DT_NIOS2_GP): New dynamic entry type for Nios II _gp address.
        (R_NIOS2_*): Define Nios II relocations.
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index 7b3e295..67dabd5 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -97,6 +97,15 @@ elf_machine_lazy_rel (struct link_map *map,
 #  define ELF_DURING_STARTUP (0)
 # endif
 
+/* Allow targets that do not have libgcc __udivsi3 available to define
+   one locally.  */
+# if defined RTLD_BOOTSTRAP && defined RTLD_BOOTSTRAP_UDIV
+#  define RTLD_UDIV(A, B) RTLD_BOOTSTRAP_UDIV (A, B)
+# else
+#  define RTLD_UDIV(A, B) ((A) / (B))
+# endif
+
+
 /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.
    These functions are almost identical, so we use cpp magic to avoid
    duplicating their code.  It cannot be done in a more general function
@@ -123,7 +132,7 @@ elf_machine_lazy_rel (struct link_map *map,
 	if (map->l_info[VERSYMIDX (DT_##RELOC##COUNT)] != NULL)		      \
 	  ranges[0].nrelative						      \
 	    = MIN (map->l_info[VERSYMIDX (DT_##RELOC##COUNT)]->d_un.d_val,    \
-		   ranges[0].size / sizeof (ElfW(reloc)));		      \
+		   RTLD_UDIV (ranges[0].size, sizeof (ElfW(reloc))));	      \
       }									      \
     if ((map)->l_info[DT_PLTREL]					      \
 	&& (!test_rel || (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC)) \
diff --git a/elf/elf.h b/elf/elf.h
index 40e87b2..85401c3 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -249,6 +249,7 @@ typedef struct
 #define EM_OPENRISC	92		/* OpenRISC 32-bit embedded processor */
 #define EM_ARC_A5	93		/* ARC Cores Tangent-A5 */
 #define EM_XTENSA	94		/* Tensilica Xtensa Architecture */
+#define EM_ALTERA_NIOS2 113		/* Altera Nios II */
 #define EM_AARCH64	183		/* ARM AARCH64 */
 #define EM_TILEPRO	188		/* Tilera TILEPro */
 #define EM_MICROBLAZE	189		/* Xilinx MicroBlaze */
@@ -3132,6 +3133,57 @@ typedef Elf32_Addr Elf32_Conflict;
 #define R_MICROBLAZE_TLSGOTTPREL32	28	/* TLS Offset From Thread Pointer. */
 #define R_MICROBLAZE_TLSTPREL32 	29	/* TLS Offset From Thread Pointer. */
 
+/* Legal values for d_tag (dynamic entry type).  */
+#define DT_NIOS2_GP             0x70000002 /* Address of _gp.  */
+
+/* Nios II relocations.  */
+#define R_NIOS2_NONE		0       /* No reloc.  */
+#define R_NIOS2_S16		1       /* Direct signed 16 bit.  */
+#define R_NIOS2_U16		2       /* Direct unsigned 16 bit.  */
+#define R_NIOS2_PCREL16		3       /* PC relative 16 bit.  */
+#define R_NIOS2_CALL26		4
+#define R_NIOS2_IMM5		5
+#define R_NIOS2_CACHE_OPX	6
+#define R_NIOS2_IMM6		7
+#define R_NIOS2_IMM8		8
+#define R_NIOS2_HI16		9
+#define R_NIOS2_LO16		10
+#define R_NIOS2_HIADJ16		11
+#define R_NIOS2_BFD_RELOC_32	12
+#define R_NIOS2_BFD_RELOC_16	13
+#define R_NIOS2_BFD_RELOC_8	14
+#define R_NIOS2_GPREL		15
+#define R_NIOS2_GNU_VTINHERIT	16
+#define R_NIOS2_GNU_VTENTRY	17
+#define R_NIOS2_UJMP		18
+#define R_NIOS2_CJMP		19
+#define R_NIOS2_CALLR		20
+#define R_NIOS2_ALIGN		21
+#define R_NIOS2_GOT16		22
+#define R_NIOS2_CALL16		23
+#define R_NIOS2_GOTOFF_LO	24
+#define R_NIOS2_GOTOFF_HA	25
+#define R_NIOS2_PCREL_LO	26
+#define R_NIOS2_PCREL_HA	27
+#define R_NIOS2_TLS_GD16	28
+#define R_NIOS2_TLS_LDM16	29
+#define R_NIOS2_TLS_LDO16	30
+#define R_NIOS2_TLS_IE16	31
+#define R_NIOS2_TLS_LE16	32
+#define R_NIOS2_TLS_DTPMOD	33
+#define R_NIOS2_TLS_DTPREL	34
+#define R_NIOS2_TLS_TPREL	35
+#define R_NIOS2_COPY		36
+#define R_NIOS2_GLOB_DAT	37
+#define R_NIOS2_JUMP_SLOT	38
+#define R_NIOS2_RELATIVE	39
+#define R_NIOS2_GOTOFF		40
+#define R_NIOS2_CALL26_NOAT	41
+#define R_NIOS2_GOT_LO		42
+#define R_NIOS2_GOT_HA		43
+#define R_NIOS2_CALL_LO		44
+#define R_NIOS2_CALL_HA		45
+
 /* TILEPro relocations.  */
 #define R_TILEPRO_NONE		0	/* No reloc */
 #define R_TILEPRO_32		1	/* Direct 32 bit */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]