Hello,

it seems that the -mcmodel=small was not the right default for RTEMS applications, since I get

relocation truncated to fit: R_PPC64_TOC16_DS against `.got'+118

errors quite quickly.

So, I try to add the -mcmodel option. However, some piece is missing:

/build/git-build/b-gcc-git-powerpc-rtems4.12/./gcc/xgcc -B/build/git-build/b-gcc-git-powerpc-rtems4.12/./gcc/ -nostdinc -B/build/git-build/b-gcc-git-powerpc-rtems4.12/powerpc-rtems4.12/me6500/m64/newlib/ -isystem /build/git-build/b-gcc-git-powerpc-rtems4.12/powerpc-rtems4.12/me6500/m64/newlib/targ-include -isystem /home/EB/sebastian_h/archive/gcc-git/newlib/libc/include -B/opt/rtems-4.12/powerpc-rtems4.12/bin/ -B/opt/rtems-4.12/powerpc-rtems4.12/lib/ -isystem /opt/rtems-4.12/powerpc-rtems4.12/include -isystem /opt/rtems-4.12/powerpc-rtems4.12/sys-include -mcpu=e6500 -m64 -g -O2 -O2 -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -I. -I. -I../../../.././gcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc/. -I/home/EB/sebastian_h/archive/gcc-git/libgcc/../gcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc/../include -g0 -finhibit-size-directive -fno-inline -fno-exceptions -fno-zero-initialized-in-bss -fno-toplevel-reorder -fno-tree-vectorize -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -I. -I. -I../../../.././gcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc/. -I/home/EB/sebastian_h/archive/gcc-git/libgcc/../gcc -I/home/EB/sebastian_h/archive/gcc-git/libgcc/../include -o crtbeginS.o -MT crtbeginS.o -MD -MP -MF crtbeginS.dep -msdata=none -O2 -c /home/EB/sebastian_h/archive/gcc-git/libgcc/crtstuff.c -DCRT_BEGIN -DCRTSTUFFS_O -fPIC -mcmodel=medium -save-temps
crtstuff.s: Assembler messages:
crtstuff.s:44: Error: can't resolve `.tm_clone_table' {.tm_clone_table section} - `.LCTOC1' {.toc1 section} crtstuff.s:45: Error: can't resolve `__TMC_END__' {*UND* section} - `.LCTOC1' {.toc1 section} crtstuff.s:82: Error: can't resolve `.tm_clone_table' {.tm_clone_table section} - `.LCTOC1' {.toc1 section} crtstuff.s:83: Error: can't resolve `__TMC_END__' {*UND* section} - `.LCTOC1' {.toc1 section} crtstuff.s:131: Error: can't resolve `.bss' {.bss section} - `.LCTOC1' {.toc1 section} crtstuff.s:143: Error: can't resolve `__dso_handle' {.sdata section} - `.LCTOC1' {.toc1 section} crtstuff.s:149: Error: can't resolve `__DTOR_END__' {*UND* section} - `.LCTOC1' {.toc1 section} crtstuff.s:150: Error: can't resolve `.dtors' {.dtors section} - `.LCTOC1' {.toc1 section} crtstuff.s:153: Error: can't resolve `.bss' {.bss section} - `.LCTOC1' {.toc1 section} crtstuff.s:157: Error: can't resolve `.dtors' {.dtors section} - `.LCTOC1' {.toc1 section} crtstuff.s:162: Error: can't resolve `.bss' {.bss section} - `.LCTOC1' {.toc1 section} crtstuff.s:185: Error: can't resolve `.eh_frame' {.eh_frame section} - `.LCTOC1' {.toc1 section} crtstuff.s:192: Error: can't resolve `.bss' {.bss section} - `.LCTOC1' {.toc1 section} crtstuff.s:226: Error: can't resolve `.bss' {.bss section} - `.LCTOC1' {.toc1 section} crtstuff.s:227: Error: can't resolve `.eh_frame' {.eh_frame section} - `.LCTOC1' {.toc1 section}

The code generation works with -mcmodel=small and -mcmodel=large.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

>From 7d2b18f303cc7cf62d29328b362e645027884270 Mon Sep 17 00:00:00 2001
From: Sebastian Huber <sebastian.hu...@embedded-brains.de>
Date: Fri, 11 Aug 2017 11:26:19 +0200
Subject: [PATCH] PowerPC/RTEMS: Enable -mcmodel option

---
 gcc/config.gcc            |  2 +-
 gcc/config/rs6000/rtems.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index a9196cd26d9..593631849bb 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2416,7 +2416,7 @@ powerpc-*-eabi*)
 	;;
 powerpc-*-rtems*)
 	tm_file="rs6000/biarch64.h ${tm_file} dbxelf.h elfos.h freebsd-spec.h newlib-stdint.h rs6000/sysv4.h rs6000/e500.h rs6000/rtems.h rtems.h"
-	extra_options="${extra_options} rs6000/sysv4.opt"
+	extra_options="${extra_options} rs6000/sysv4.opt rs6000/linux64.opt"
 	tmake_file="${tmake_file} rs6000/t-fprules rs6000/t-rtems rs6000/t-ppccomm"
 	;;
 powerpc*-*-linux*)
diff --git a/gcc/config/rs6000/rtems.h b/gcc/config/rs6000/rtems.h
index 8a62fdcbaf3..40940c1dfe6 100644
--- a/gcc/config/rs6000/rtems.h
+++ b/gcc/config/rs6000/rtems.h
@@ -37,6 +37,11 @@
 #undef	TARGET_AIX
 #define	TARGET_AIX TARGET_64BIT
 
+/* Copy and paste from linux64.h and freebsd64.h */
+#undef TARGET_CMODEL
+#define TARGET_CMODEL rs6000_current_cmodel
+#define SET_CMODEL(opt) rs6000_current_cmodel = opt
+
 #undef TARGET_OS_CPP_BUILTINS
 #define TARGET_OS_CPP_BUILTINS()			\
   do							\
@@ -95,6 +100,24 @@
 	      rs6000_isa_flags |= OPTION_MASK_POWERPC64;	\
 	      error ("-m64 requires a PowerPC64 cpu");		\
 	    }							\
+	  if ((rs6000_isa_flags_explicit			\
+		& OPTION_MASK_MINIMAL_TOC) != 0)		\
+	    {							\
+	      if (global_options_set.x_rs6000_current_cmodel	\
+		  && rs6000_current_cmodel != CMODEL_SMALL)	\
+		error ("-mcmodel incompatible with other toc options"); \
+	      SET_CMODEL (CMODEL_SMALL);			\
+	    }							\
+	  else							\
+	    {							\
+	      if (!global_options_set.x_rs6000_current_cmodel)	\
+		SET_CMODEL (CMODEL_MEDIUM);			\
+	      if (rs6000_current_cmodel != CMODEL_SMALL)	\
+		{						\
+		  TARGET_NO_FP_IN_TOC = 0;			\
+		  TARGET_NO_SUM_IN_TOC = 0;			\
+		}						\
+	    }							\
 	}							\
     }								\
   while (0)
@@ -141,6 +164,30 @@
 #define RESTORE_FP_SUFFIX ""
 
 /* Copy and paste from linux64.h and freebsd64.h */
+#undef	ASM_PREFERRED_EH_DATA_FORMAT
+#define	ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
+  (TARGET_64BIT || flag_pic						\
+   ? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel		\
+      | (TARGET_64BIT ? DW_EH_PE_udata8 : DW_EH_PE_sdata4))		\
+   : DW_EH_PE_absptr)
+
+/* Copy and paste from linux64.h and freebsd64.h */
+#undef  TOC_SECTION_ASM_OP
+#define TOC_SECTION_ASM_OP \
+  (TARGET_64BIT						\
+   ? "\t.section\t\".toc\",\"aw\""			\
+   : "\t.section\t\".got\",\"aw\"")
+
+/* Copy and paste from linux64.h and freebsd64.h */
+#undef  MINIMAL_TOC_SECTION_ASM_OP
+#define MINIMAL_TOC_SECTION_ASM_OP \
+  (TARGET_64BIT						\
+   ? "\t.section\t\".toc1\",\"aw\""			\
+   : (flag_pic						\
+      ? "\t.section\t\".got2\",\"aw\""			\
+      : "\t.section\t\".got1\",\"aw\""))
+
+/* Copy and paste from linux64.h and freebsd64.h */
 #undef	ASM_DECLARE_FUNCTION_SIZE
 #define	ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
   do									\
-- 
2.12.3

	.file	"crtstuff.c"
	.abiversion 2
	.section	.ctors,"aw",@progbits
	.align 3
	.type	__CTOR_LIST__, @object
__CTOR_LIST__:
	.quad	-1
	.section	.dtors,"aw",@progbits
	.align 3
	.type	__DTOR_LIST__, @object
__DTOR_LIST__:
	.quad	-1
	.section	.eh_frame,"a",@progbits
	.align 2
	.type	__EH_FRAME_BEGIN__, @object
__EH_FRAME_BEGIN__:
	.section	.tm_clone_table,"aw",@progbits
	.align 3
	.type	__TMC_LIST__, @object
__TMC_LIST__:
	.section	".toc","aw"
	.align 3
.LCTOC0:
	.tc .LCTOC1[TC],.LCTOC1
	.section	".toc1","aw"
	.align 3
.LCTOC1 = .+32768
.LC0:
	.quad	_ITM_deregisterTMCloneTable
	.section	".text"
	.align 2
	.p2align 4,,15
	.type	deregister_tm_clones, @function
deregister_tm_clones:
.LCF0:
0:	addis 2,12,.TOC.-.LCF0@ha
	addi 2,2,.TOC.-.LCF0@l
	.localentry	deregister_tm_clones,.-deregister_tm_clones
	std 30,-16(1)
	ld 30,.LCTOC0@toc(2)
	stdu 1,-48(1)
	addis 3,30,__TMC_LIST__@toc@ha
	addis 9,30,__TMC_END__@toc@ha
	addi 3,3,__TMC_LIST__-.LCTOC1@l
	addi 9,9,__TMC_END__-.LCTOC1@l
	cmpd 7,9,3
	beq- 7,.L1
	addis 9,30,.LC0@toc@ha
	ld 9,.LC0-.LCTOC1@l(9)
	cmpdi 7,9,0
	beq- 7,.L1
	mflr 0
	std 2,24(1)
	std 0,64(1)
	mr 12,9
	mtctr 9
	bctrl
	ld 2,24(1)
	ld 0,64(1)
	mtlr 0
.L1:
	addi 1,1,48
	ld 30,-16(1)
	blr
	.section	".toc1","aw"
.LC1:
	.quad	_ITM_registerTMCloneTable
	.section	".text"
	.align 2
	.p2align 4,,15
	.type	register_tm_clones, @function
register_tm_clones:
.LCF1:
0:	addis 2,12,.TOC.-.LCF1@ha
	addi 2,2,.TOC.-.LCF1@l
	.localentry	register_tm_clones,.-register_tm_clones
	std 30,-16(1)
	ld 30,.LCTOC0@toc(2)
	stdu 1,-48(1)
	addis 3,30,__TMC_LIST__@toc@ha
	addis 4,30,__TMC_END__@toc@ha
	addi 3,3,__TMC_LIST__-.LCTOC1@l
	addi 4,4,__TMC_END__-.LCTOC1@l
	subf 4,3,4
	sradi 4,4,3
	sradi 4,4,1
	addze. 4,4
	beq- 0,.L8
	addis 9,30,.LC1@toc@ha
	ld 9,.LC1-.LCTOC1@l(9)
	cmpdi 7,9,0
	beq- 7,.L8
	mflr 0
	std 2,24(1)
	std 0,64(1)
	mr 12,9
	mtctr 9
	bctrl
	ld 2,24(1)
	ld 0,64(1)
	mtlr 0
.L8:
	addi 1,1,48
	ld 30,-16(1)
	blr
	.hidden	__dso_handle
	.globl __dso_handle
	.section	.sdata,"aw",@progbits
	.align 3
	.type	__dso_handle, @object
__dso_handle:
	.quad	__dso_handle
	.section	".toc1","aw"
.LC2:
	.quad	__cxa_finalize
.LC3:
	.quad	__deregister_frame_info
	.section	".text"
	.align 2
	.p2align 4,,15
	.type	__do_global_dtors_aux, @function
__do_global_dtors_aux:
.LCF2:
0:	addis 2,12,.TOC.-.LCF2@ha
	addi 2,2,.TOC.-.LCF2@l
	.localentry	__do_global_dtors_aux,.-__do_global_dtors_aux
	std 30,-16(1)
	ld 30,.LCTOC0@toc(2)
	stdu 1,-64(1)
	addis 9,30,completed.6203@toc@ha
	lbz 9,completed.6203-.LCTOC1@l(9)
	cmpwi 7,9,0
	bne- 7,.L17
	addis 9,30,.LC2@toc@ha
	mflr 0
	ld 9,.LC2-.LCTOC1@l(9)
	std 0,80(1)
	std 28,32(1)
	cmpdi 7,9,0
	std 31,56(1)
	beq- 7,.L19
	addis 9,30,__dso_handle@toc@ha
	ld 3,__dso_handle-.LCTOC1@l(9)
	bl __cxa_finalize
	nop
.L19:
	addis 9,30,__DTOR_END__@toc@ha
	addis 31,30,__DTOR_LIST__@toc@ha
	addi 9,9,__DTOR_END__-.LCTOC1@l
	addi 31,31,__DTOR_LIST__-.LCTOC1@l
	subf 31,31,9
	addis 9,30,dtor_idx.6205@toc@ha
	ld 9,dtor_idx.6205-.LCTOC1@l(9)
	sradi 31,31,3
	addi 31,31,-1
	addis 28,30,__DTOR_LIST__@toc@ha
	addi 28,28,__DTOR_LIST__-.LCTOC1@l
	cmpld 7,9,31
	bge- 7,.L20
	std 29,40(1)
	addis 29,30,dtor_idx.6205@toc@ha
	addi 29,29,dtor_idx.6205-.LCTOC1@l
	.p2align 4,,15
.L21:
	addi 9,9,1
	sldi 10,9,3
	std 9,0(29)
	ldx 9,28,10
	std 2,24(1)
	mr 12,9
	mtctr 9
	bctrl
	ld 2,24(1)
	ld 9,0(29)
	cmpld 7,9,31
	blt+ 7,.L21
	ld 29,40(1)
.L20:
	bl deregister_tm_clones
	addis 9,30,.LC3@toc@ha
	ld 9,.LC3-.LCTOC1@l(9)
	cmpdi 7,9,0
	beq- 7,.L22
	addis 3,30,__EH_FRAME_BEGIN__@toc@ha
	addi 3,3,__EH_FRAME_BEGIN__-.LCTOC1@l
	bl __deregister_frame_info
	nop
.L22:
	li 9,1
	addis 10,30,completed.6203@toc@ha
	ld 0,80(1)
	stb 9,completed.6203-.LCTOC1@l(10)
	ld 28,32(1)
	ld 31,56(1)
	mtlr 0
.L17:
	addi 1,1,64
	ld 30,-16(1)
	blr
	.section	".fini","ax"
	bl __do_global_dtors_aux
	nop
	.previous
	.section	".toc1","aw"
.LC4:
	.quad	__register_frame_info
	.section	".text"
	.align 2
	.p2align 4,,15
	.type	frame_dummy, @function
frame_dummy:
.LCF3:
0:	addis 2,12,.TOC.-.LCF3@ha
	addi 2,2,.TOC.-.LCF3@l
	.localentry	frame_dummy,.-frame_dummy
	std 30,-16(1)
	ld 30,.LCTOC0@toc(2)
	stdu 1,-48(1)
	addis 9,30,.LC4@toc@ha
	ld 9,.LC4-.LCTOC1@l(9)
	cmpdi 7,9,0
	beq- 7,.L32
	addis 4,30,object.6215@toc@ha
	addis 3,30,__EH_FRAME_BEGIN__@toc@ha
	mflr 0
	addi 4,4,object.6215-.LCTOC1@l
	addi 3,3,__EH_FRAME_BEGIN__-.LCTOC1@l
	std 0,64(1)
	bl __register_frame_info
	nop
	ld 0,64(1)
	mtlr 0
.L32:
	addi 1,1,48
	ld 30,-16(1)
	b register_tm_clones
	.section	".init","ax"
	bl frame_dummy
	nop
	.previous
	.lcomm	completed.6203,1,1
	.type	completed.6203, @object
	.lcomm	dtor_idx.6205,8,8
	.type	dtor_idx.6205, @object
	.lcomm	object.6215,48,8
	.type	object.6215, @object
	.weak	__register_frame_info
	.weak	__deregister_frame_info
	.weak	__cxa_finalize
	.weak	_ITM_registerTMCloneTable
	.weak	_ITM_deregisterTMCloneTable
	.hidden	__DTOR_END__
	.hidden	__TMC_END__
	.ident	"GCC: (GNU) 7.1.1 20170810 [gcc-7-branch revision e363899ddbf:1a4de6af07d:e943bd58a59a930f8708f844e1e352629a4a20f7]"
	.section	.note.GNU-stack,"",@progbits

Reply via email to