Re: arm-none-eabi-gcc 5.3 and LTO, mixing ARM and Thumb instructions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



My apologies, I forgot to attach the files.



----- Original Message -----
From: Gabriel Marcano <gabemarcano@xxxxxxxxx>
To: "gcc-help@xxxxxxxxxxx" <gcc-help@xxxxxxxxxxx>
Sent: Wednesday, June 1, 2016 7:23 PM
Subject: arm-none-eabi-gcc 5.3 and LTO, mixing ARM and Thumb instructions

Could someone help me understand this behavior with LTO? I am working with an
ARM cross compiler, arm-none-eabi. I am trying to make the compiler compile two
separate files in different ARM modes/targets, one of them in ARM, one of them
in Thumb. When I compile the two source files without -flto, one with -mthumb 
-thumb-interwork, and the other with the same flags just -marm appended as to
override -mthumb, the resulting binary, when dissasembled with objdump, has code
in both modes, and it is rather aparent. When I enable -flto, the resulting
program ends up in a single mode, all of it.

I am attaching a couple of files to this email:
  arm.c      : The file to be compiled as ARM
  main.c     : The main function, compiled as Thumb
  Makefile   : Add -flto to LDFLAGS and CFLAGS to enable lto, remvove it to
               disable it.
  lto.txt    : The arm-none-eabi-objdump dissassembly of the resulting lto
               binary.
  no-lto.txt : the arm-none-eabi-objdump dissassembly of the resulting binary
               without lto.

Is there something obvious about the behavior of LTO that I'm missing? Does it
just generate the final machine code at link time, scrapping the flags used to
compile object files?

Thanks,

Gabriel E. Marcano
int foo(int a, int b)
{
	return a + b;
}
main:     file format elf32-littlearm


Disassembly of section .init:

00008000 <_init>:
    8000:	b5f8      	push	{r3, r4, r5, r6, r7, lr}
    8002:	46c0      	nop			; (mov r8, r8)
    8004:	bcf8      	pop	{r3, r4, r5, r6, r7}
    8006:	bc08      	pop	{r3}
    8008:	469e      	mov	lr, r3
    800a:	4770      	bx	lr

Disassembly of section .text:

0000800c <deregister_tm_clones>:
    800c:	4b07      	ldr	r3, [pc, #28]	; (802c <deregister_tm_clones+0x20>)
    800e:	4808      	ldr	r0, [pc, #32]	; (8030 <deregister_tm_clones+0x24>)
    8010:	3303      	adds	r3, #3
    8012:	b510      	push	{r4, lr}
    8014:	1a1b      	subs	r3, r3, r0
    8016:	2b06      	cmp	r3, #6
    8018:	d904      	bls.n	8024 <deregister_tm_clones+0x18>
    801a:	4b06      	ldr	r3, [pc, #24]	; (8034 <deregister_tm_clones+0x28>)
    801c:	2b00      	cmp	r3, #0
    801e:	d001      	beq.n	8024 <deregister_tm_clones+0x18>
    8020:	f000 f85c 	bl	80dc <frame_dummy+0x44>
    8024:	bc10      	pop	{r4}
    8026:	bc01      	pop	{r0}
    8028:	4700      	bx	r0
    802a:	46c0      	nop			; (mov r8, r8)
    802c:	00018140 	.word	0x00018140
    8030:	00018140 	.word	0x00018140
    8034:	00000000 	.word	0x00000000

00008038 <register_tm_clones>:
    8038:	4808      	ldr	r0, [pc, #32]	; (805c <register_tm_clones+0x24>)
    803a:	4909      	ldr	r1, [pc, #36]	; (8060 <register_tm_clones+0x28>)
    803c:	1a09      	subs	r1, r1, r0
    803e:	1089      	asrs	r1, r1, #2
    8040:	0fcb      	lsrs	r3, r1, #31
    8042:	1859      	adds	r1, r3, r1
    8044:	b510      	push	{r4, lr}
    8046:	1049      	asrs	r1, r1, #1
    8048:	d004      	beq.n	8054 <register_tm_clones+0x1c>
    804a:	4b06      	ldr	r3, [pc, #24]	; (8064 <register_tm_clones+0x2c>)
    804c:	2b00      	cmp	r3, #0
    804e:	d001      	beq.n	8054 <register_tm_clones+0x1c>
    8050:	f000 f844 	bl	80dc <frame_dummy+0x44>
    8054:	bc10      	pop	{r4}
    8056:	bc01      	pop	{r0}
    8058:	4700      	bx	r0
    805a:	46c0      	nop			; (mov r8, r8)
    805c:	00018140 	.word	0x00018140
    8060:	00018140 	.word	0x00018140
    8064:	00000000 	.word	0x00000000

00008068 <__do_global_dtors_aux>:
    8068:	b510      	push	{r4, lr}
    806a:	4c08      	ldr	r4, [pc, #32]	; (808c <__do_global_dtors_aux+0x24>)
    806c:	7823      	ldrb	r3, [r4, #0]
    806e:	2b00      	cmp	r3, #0
    8070:	d109      	bne.n	8086 <__do_global_dtors_aux+0x1e>
    8072:	f7ff ffcb 	bl	800c <deregister_tm_clones>
    8076:	4b06      	ldr	r3, [pc, #24]	; (8090 <__do_global_dtors_aux+0x28>)
    8078:	2b00      	cmp	r3, #0
    807a:	d002      	beq.n	8082 <__do_global_dtors_aux+0x1a>
    807c:	4805      	ldr	r0, [pc, #20]	; (8094 <__do_global_dtors_aux+0x2c>)
    807e:	e000      	b.n	8082 <__do_global_dtors_aux+0x1a>
    8080:	bf00      	nop
    8082:	2301      	movs	r3, #1
    8084:	7023      	strb	r3, [r4, #0]
    8086:	bc10      	pop	{r4}
    8088:	bc01      	pop	{r0}
    808a:	4700      	bx	r0
    808c:	00018140 	.word	0x00018140
    8090:	00000000 	.word	0x00000000
    8094:	0000812c 	.word	0x0000812c

00008098 <frame_dummy>:
    8098:	4b0b      	ldr	r3, [pc, #44]	; (80c8 <frame_dummy+0x30>)
    809a:	b510      	push	{r4, lr}
    809c:	2b00      	cmp	r3, #0
    809e:	d003      	beq.n	80a8 <frame_dummy+0x10>
    80a0:	490a      	ldr	r1, [pc, #40]	; (80cc <frame_dummy+0x34>)
    80a2:	480b      	ldr	r0, [pc, #44]	; (80d0 <frame_dummy+0x38>)
    80a4:	e000      	b.n	80a8 <frame_dummy+0x10>
    80a6:	bf00      	nop
    80a8:	480a      	ldr	r0, [pc, #40]	; (80d4 <frame_dummy+0x3c>)
    80aa:	6803      	ldr	r3, [r0, #0]
    80ac:	2b00      	cmp	r3, #0
    80ae:	d104      	bne.n	80ba <frame_dummy+0x22>
    80b0:	f7ff ffc2 	bl	8038 <register_tm_clones>
    80b4:	bc10      	pop	{r4}
    80b6:	bc01      	pop	{r0}
    80b8:	4700      	bx	r0
    80ba:	4b07      	ldr	r3, [pc, #28]	; (80d8 <frame_dummy+0x40>)
    80bc:	2b00      	cmp	r3, #0
    80be:	d0f7      	beq.n	80b0 <frame_dummy+0x18>
    80c0:	f000 f80c 	bl	80dc <frame_dummy+0x44>
    80c4:	e7f4      	b.n	80b0 <frame_dummy+0x18>
    80c6:	46c0      	nop			; (mov r8, r8)
    80c8:	00000000 	.word	0x00000000
    80cc:	00018144 	.word	0x00018144
    80d0:	0000812c 	.word	0x0000812c
    80d4:	00018138 	.word	0x00018138
    80d8:	00000000 	.word	0x00000000
    80dc:	4718      	bx	r3
    80de:	46c0      	nop			; (mov r8, r8)

000080e0 <main>:
    80e0:	b580      	push	{r7, lr}
    80e2:	af00      	add	r7, sp, #0
    80e4:	4a05      	ldr	r2, [pc, #20]	; (80fc <main+0x1c>)
    80e6:	4b06      	ldr	r3, [pc, #24]	; (8100 <main+0x20>)
    80e8:	0011      	movs	r1, r2
    80ea:	0018      	movs	r0, r3
    80ec:	f000 f80a 	bl	8104 <foo>
    80f0:	0003      	movs	r3, r0
    80f2:	0018      	movs	r0, r3
    80f4:	46bd      	mov	sp, r7
    80f6:	bc80      	pop	{r7}
    80f8:	bc02      	pop	{r1}
    80fa:	4708      	bx	r1
    80fc:	0000beef 	.word	0x0000beef
    8100:	0000dead 	.word	0x0000dead

00008104 <foo>:
    8104:	b580      	push	{r7, lr}
    8106:	b082      	sub	sp, #8
    8108:	af00      	add	r7, sp, #0
    810a:	6078      	str	r0, [r7, #4]
    810c:	6039      	str	r1, [r7, #0]
    810e:	687a      	ldr	r2, [r7, #4]
    8110:	683b      	ldr	r3, [r7, #0]
    8112:	18d3      	adds	r3, r2, r3
    8114:	0018      	movs	r0, r3
    8116:	46bd      	mov	sp, r7
    8118:	b002      	add	sp, #8
    811a:	bc80      	pop	{r7}
    811c:	bc02      	pop	{r1}
    811e:	4708      	bx	r1

Disassembly of section .fini:

00008120 <_fini>:
    8120:	b5f8      	push	{r3, r4, r5, r6, r7, lr}
    8122:	46c0      	nop			; (mov r8, r8)
    8124:	bcf8      	pop	{r3, r4, r5, r6, r7}
    8126:	bc08      	pop	{r3}
    8128:	469e      	mov	lr, r3
    812a:	4770      	bx	lr
int foo(int a, int b);

int main()
{
	return foo(0xDEAD, 0xBEEF);
}

Attachment: Makefile
Description: Binary data

main:     file format elf32-littlearm


Disassembly of section .init:

00008000 <_init>:
    8000:	b5f8      	push	{r3, r4, r5, r6, r7, lr}
    8002:	46c0      	nop			; (mov r8, r8)
    8004:	bcf8      	pop	{r3, r4, r5, r6, r7}
    8006:	bc08      	pop	{r3}
    8008:	469e      	mov	lr, r3
    800a:	4770      	bx	lr

Disassembly of section .text:

00008010 <deregister_tm_clones>:
    8010:	4b07      	ldr	r3, [pc, #28]	; (8030 <deregister_tm_clones+0x20>)
    8012:	4808      	ldr	r0, [pc, #32]	; (8034 <deregister_tm_clones+0x24>)
    8014:	3303      	adds	r3, #3
    8016:	b510      	push	{r4, lr}
    8018:	1a1b      	subs	r3, r3, r0
    801a:	2b06      	cmp	r3, #6
    801c:	d904      	bls.n	8028 <deregister_tm_clones+0x18>
    801e:	4b06      	ldr	r3, [pc, #24]	; (8038 <deregister_tm_clones+0x28>)
    8020:	2b00      	cmp	r3, #0
    8022:	d001      	beq.n	8028 <deregister_tm_clones+0x18>
    8024:	f000 f85c 	bl	80e0 <frame_dummy+0x44>
    8028:	bc10      	pop	{r4}
    802a:	bc01      	pop	{r0}
    802c:	4700      	bx	r0
    802e:	46c0      	nop			; (mov r8, r8)
    8030:	00018160 	.word	0x00018160
    8034:	00018160 	.word	0x00018160
    8038:	00000000 	.word	0x00000000

0000803c <register_tm_clones>:
    803c:	4808      	ldr	r0, [pc, #32]	; (8060 <register_tm_clones+0x24>)
    803e:	4909      	ldr	r1, [pc, #36]	; (8064 <register_tm_clones+0x28>)
    8040:	1a09      	subs	r1, r1, r0
    8042:	1089      	asrs	r1, r1, #2
    8044:	0fcb      	lsrs	r3, r1, #31
    8046:	1859      	adds	r1, r3, r1
    8048:	b510      	push	{r4, lr}
    804a:	1049      	asrs	r1, r1, #1
    804c:	d004      	beq.n	8058 <register_tm_clones+0x1c>
    804e:	4b06      	ldr	r3, [pc, #24]	; (8068 <register_tm_clones+0x2c>)
    8050:	2b00      	cmp	r3, #0
    8052:	d001      	beq.n	8058 <register_tm_clones+0x1c>
    8054:	f000 f844 	bl	80e0 <frame_dummy+0x44>
    8058:	bc10      	pop	{r4}
    805a:	bc01      	pop	{r0}
    805c:	4700      	bx	r0
    805e:	46c0      	nop			; (mov r8, r8)
    8060:	00018160 	.word	0x00018160
    8064:	00018160 	.word	0x00018160
    8068:	00000000 	.word	0x00000000

0000806c <__do_global_dtors_aux>:
    806c:	b510      	push	{r4, lr}
    806e:	4c08      	ldr	r4, [pc, #32]	; (8090 <__do_global_dtors_aux+0x24>)
    8070:	7823      	ldrb	r3, [r4, #0]
    8072:	2b00      	cmp	r3, #0
    8074:	d109      	bne.n	808a <__do_global_dtors_aux+0x1e>
    8076:	f7ff ffcb 	bl	8010 <deregister_tm_clones>
    807a:	4b06      	ldr	r3, [pc, #24]	; (8094 <__do_global_dtors_aux+0x28>)
    807c:	2b00      	cmp	r3, #0
    807e:	d002      	beq.n	8086 <__do_global_dtors_aux+0x1a>
    8080:	4805      	ldr	r0, [pc, #20]	; (8098 <__do_global_dtors_aux+0x2c>)
    8082:	e000      	b.n	8086 <__do_global_dtors_aux+0x1a>
    8084:	bf00      	nop
    8086:	2301      	movs	r3, #1
    8088:	7023      	strb	r3, [r4, #0]
    808a:	bc10      	pop	{r4}
    808c:	bc01      	pop	{r0}
    808e:	4700      	bx	r0
    8090:	00018160 	.word	0x00018160
    8094:	00000000 	.word	0x00000000
    8098:	0000814c 	.word	0x0000814c

0000809c <frame_dummy>:
    809c:	4b0b      	ldr	r3, [pc, #44]	; (80cc <frame_dummy+0x30>)
    809e:	b510      	push	{r4, lr}
    80a0:	2b00      	cmp	r3, #0
    80a2:	d003      	beq.n	80ac <frame_dummy+0x10>
    80a4:	490a      	ldr	r1, [pc, #40]	; (80d0 <frame_dummy+0x34>)
    80a6:	480b      	ldr	r0, [pc, #44]	; (80d4 <frame_dummy+0x38>)
    80a8:	e000      	b.n	80ac <frame_dummy+0x10>
    80aa:	bf00      	nop
    80ac:	480a      	ldr	r0, [pc, #40]	; (80d8 <frame_dummy+0x3c>)
    80ae:	6803      	ldr	r3, [r0, #0]
    80b0:	2b00      	cmp	r3, #0
    80b2:	d104      	bne.n	80be <frame_dummy+0x22>
    80b4:	f7ff ffc2 	bl	803c <register_tm_clones>
    80b8:	bc10      	pop	{r4}
    80ba:	bc01      	pop	{r0}
    80bc:	4700      	bx	r0
    80be:	4b07      	ldr	r3, [pc, #28]	; (80dc <frame_dummy+0x40>)
    80c0:	2b00      	cmp	r3, #0
    80c2:	d0f7      	beq.n	80b4 <frame_dummy+0x18>
    80c4:	f000 f80c 	bl	80e0 <frame_dummy+0x44>
    80c8:	e7f4      	b.n	80b4 <frame_dummy+0x18>
    80ca:	46c0      	nop			; (mov r8, r8)
    80cc:	00000000 	.word	0x00000000
    80d0:	00018164 	.word	0x00018164
    80d4:	0000814c 	.word	0x0000814c
    80d8:	00018158 	.word	0x00018158
    80dc:	00000000 	.word	0x00000000
    80e0:	4718      	bx	r3
    80e2:	46c0      	nop			; (mov r8, r8)

000080e4 <main>:
    80e4:	b580      	push	{r7, lr}
    80e6:	af00      	add	r7, sp, #0
    80e8:	4a05      	ldr	r2, [pc, #20]	; (8100 <main+0x1c>)
    80ea:	4b06      	ldr	r3, [pc, #24]	; (8104 <main+0x20>)
    80ec:	0011      	movs	r1, r2
    80ee:	0018      	movs	r0, r3
    80f0:	f000 f822 	bl	8138 <__foo_from_thumb>
    80f4:	0003      	movs	r3, r0
    80f6:	0018      	movs	r0, r3
    80f8:	46bd      	mov	sp, r7
    80fa:	bc80      	pop	{r7}
    80fc:	bc02      	pop	{r1}
    80fe:	4708      	bx	r1
    8100:	0000beef 	.word	0x0000beef
    8104:	0000dead 	.word	0x0000dead

00008108 <foo>:
    8108:	e52db004 	push	{fp}		; (str fp, [sp, #-4]!)
    810c:	e28db000 	add	fp, sp, #0
    8110:	e24dd00c 	sub	sp, sp, #12
    8114:	e50b0008 	str	r0, [fp, #-8]
    8118:	e50b100c 	str	r1, [fp, #-12]
    811c:	e51b2008 	ldr	r2, [fp, #-8]
    8120:	e51b300c 	ldr	r3, [fp, #-12]
    8124:	e0823003 	add	r3, r2, r3
    8128:	e1a00003 	mov	r0, r3
    812c:	e24bd000 	sub	sp, fp, #0
    8130:	e49db004 	pop	{fp}		; (ldr fp, [sp], #4)
    8134:	e12fff1e 	bx	lr

00008138 <__foo_from_thumb>:
    8138:	4778      	bx	pc
    813a:	46c0      	nop			; (mov r8, r8)
    813c:	eafffff1 	b	8108 <foo>

Disassembly of section .fini:

00008140 <_fini>:
    8140:	b5f8      	push	{r3, r4, r5, r6, r7, lr}
    8142:	46c0      	nop			; (mov r8, r8)
    8144:	bcf8      	pop	{r3, r4, r5, r6, r7}
    8146:	bc08      	pop	{r3}
    8148:	469e      	mov	lr, r3
    814a:	4770      	bx	lr

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux