Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #127401

Re: Compile Assembly and C files together

Subject Re: Compile Assembly and C files together
Newsgroups comp.lang.c
References (3 earlier) <20180306145910.01512e6b@Mars> <p7mcge$oci$1@dont-email.me> <09640d63-f1b3-43c5-970d-4ac66db41cf3@googlegroups.com> <hrznC.15256$5c2.6550@fx09.am4> <slrnp9tmm0.eu5.grahn+nntp@frailea.sa.invalid>
From bartc <bc@freeuk.com>
Message-ID <MqBnC.71797$_P3.20721@fx28.am4> (permalink)
Organization virginmedia.com
Date 2018-03-06 18:51 +0000

Show all headers | View raw


On 06/03/2018 18:15, Jorgen Grahn wrote:
> On Tue, 2018-03-06, bartc wrote:

>> The important thing though is not to let gcc optimise the code.
> 
> Why?  The optimization level cannot change the calling conventions, or
> you'd need a copy of e.g. the standard library for each optimization
> setting.

There's a huge amount that gcc can do to render the asm output 
incomprehensible. Here's a very simple example:

   extern int fnx(int,int);

   int fna(int a,int b){
     return fnx(a,b);
   }

We're interested in the asm framework of the fna function. Compiled with 
-O0 for x86 (as I don't have ARM handy) you get:

	.text
	.globl	fna
	.def	fna;	.scl	2;	.type	32;	.endef
	.seh_proc	fna
fna:
	push	rbp	 #
	.seh_pushreg	rbp
	mov	rbp, rsp	 #,
	.seh_setframe	rbp, 0
	sub	rsp, 32	 #,
	.seh_stackalloc	32
	.seh_endprologue
	mov	DWORD PTR 16[rbp], ecx	 # a, a
	mov	DWORD PTR 24[rbp], edx	 # b, b
	mov	eax, DWORD PTR 24[rbp]	 # tmp89, b
	mov	edx, eax	 #, tmp89
	mov	ecx, DWORD PTR 16[rbp]	 #, a
	call	fnx	 #
	add	rsp, 32	 #,
	pop	rbp	 #
	ret
	.seh_endproc

You can clearly make out the entry and return sequence, and how the call 
to fnx is set up. Remember that the intention is to augment or modify 
this with extra code written in ASM.

Now look at the same code compiled with -O3:

	.text
.LHOTB0:
	.p2align 4,,15
	.globl	fna
	.def	fna;	.scl	2;	.type	32;	.endef
	.seh_proc	fna
fna:
	.seh_endprologue
	jmp	fnx	 #
	.seh_endproc

It's optimised it pretty much out of existence. All that's left is the 
label.

-- 
bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compile Assembly and C files together Ilias Abrams <iliasabrams@gmail.com> - 2018-03-05 08:23 -0800
  Re: Compile Assembly and C files together "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2018-03-06 19:20 +0800
    Re: Compile Assembly and C files together druck <news@druck.org.uk> - 2018-03-06 13:53 +0000
      Re: Compile Assembly and C files together Rob Morley <nospam@ntlworld.com> - 2018-03-06 14:59 +0000
        Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-06 16:35 +0100
          Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-06 07:57 -0800
            Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-06 16:35 +0000
              Re: Compile Assembly and C files together Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-06 18:15 +0000
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-06 18:51 +0000
                Re: Compile Assembly and C files together Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-06 19:22 +0000
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-06 19:30 +0000
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-06 12:31 -0800
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-06 23:05 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 12:17 +0100
                Re: Compile Assembly and C files together Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-07 16:05 +0000
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-07 16:45 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 17:54 +0100
                Re: Compile Assembly and C files together Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-07 16:59 +0000
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-07 17:13 +0000
              Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 12:26 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-07 14:25 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 15:57 +0100
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-07 15:24 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 17:56 +0100
            Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 11:37 +0100
              Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-07 13:11 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-07 15:47 +0100
                Re: Compile Assembly and C files together Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-03-07 07:31 -0800
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-07 21:00 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-08 12:33 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-08 13:05 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-08 15:14 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-08 15:23 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-08 23:22 +0100
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-08 14:40 -0800
                Re: Compile Assembly and C files together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-08 23:59 +0000
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-08 16:54 -0800
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-09 10:37 +0100
                Re: Compile Assembly and C files together Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-03-09 10:47 +0000
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-09 09:19 -0800
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-09 10:23 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-09 12:28 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-09 16:43 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-09 17:14 +0000
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-09 09:32 -0800
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-08 15:26 +0000
                Re: Compile Assembly and C files together Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-03-08 19:23 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-08 23:27 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-08 16:17 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-08 23:47 +0100
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-09 11:59 +0000
              Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-07 09:13 -0800
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-07 17:42 +0000
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-07 10:55 -0800
      Re: Compile Assembly and C files together "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2018-03-06 23:01 +0800
    Re: Compile Assembly and C files together ray carter <ray@zianet.com> - 2018-03-06 15:44 +0000
      Re: Compile Assembly and C files together "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2018-03-07 00:07 +0800
        Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-07 22:39 +0200
          Re: Compile Assembly and C files together "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2018-03-08 18:18 +0800
            Re: Compile Assembly and C files together Martin Gregorie <martin@mydomain.invalid> - 2018-03-08 12:37 +0000
              Re: Compile Assembly and C files together Martin Gregorie <martin@mydomain.invalid> - 2018-03-08 13:13 +0000
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-08 13:34 +0000
                Re: Compile Assembly and C files together Martin Gregorie <martin@mydomain.invalid> - 2018-03-08 15:27 +0000
                Re: Compile Assembly and C files together mm0fmf <none@invalid.com> - 2018-03-08 17:33 +0000
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 09:06 +0000
                Re: Compile Assembly and C files together Richard Kettlewell <invalid@invalid.invalid> - 2018-03-09 09:17 +0000
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 09:30 +0000
                Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-09 15:56 +0200
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-09 14:13 +0000
                Re: Compile Assembly and C files together Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2018-03-09 11:14 -0500
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 17:44 +0000
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-09 17:16 +0100
                Re: Compile Assembly and C files together Robert Wessel <robertwessel2@yahoo.com> - 2018-03-09 11:19 -0600
                Re: Compile Assembly and C files together bartc <bc@freeuk.com> - 2018-03-09 18:11 +0000
                Re: Compile Assembly and C files together Robert Wessel <robertwessel2@yahoo.com> - 2018-03-09 13:41 -0600
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-09 10:12 -0800
                Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-09 19:20 +0100
                Re: Compile Assembly and C files together supercat@casperkitty.com - 2018-03-09 11:45 -0800
                Re: Compile Assembly and C files together Robert Wessel <robertwessel2@yahoo.com> - 2018-03-09 13:48 -0600
                Re: Compile Assembly and C files together Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2018-03-09 13:16 -0500
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-09 18:29 +0000
                Re: Compile Assembly and C files together Jack Fearnley <jack@alcor.concordia.ca> - 2018-03-09 19:07 +0000
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-09 19:13 +0000
                Re: Compile Assembly and C files together Michael J. Mahon <mjmahon@aol.com> - 2018-03-10 13:16 -0600
                Re: Compile Assembly and C files together Martin Gregorie <martin@mydomain.invalid> - 2018-03-11 19:39 +0000
                Re: Compile Assembly and C files together Michael J. Mahon <mjmahon@aol.com> - 2018-03-12 01:16 -0500
                Re: Compile Assembly and C files together Martin Gregorie <martin@mydomain.invalid> - 2018-03-12 20:49 +0000
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-12 16:11 +0000
                Re: Compile Assembly and C files together Michael J. Mahon <mjmahon@aol.com> - 2018-03-12 14:58 -0500
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-12 20:38 +0000
                Re: Compile Assembly and C files together scott@slp53.sl.home (Scott Lurndal) - 2018-03-12 16:06 +0000
                Re: Compile Assembly and C files together Michael J. Mahon <mjmahon@aol.com> - 2018-03-12 14:58 -0500
                Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-09 21:27 +0200
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 17:40 +0000
                Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-09 21:30 +0200
                Re: Compile Assembly and C files together Richard Damon <Richard@Damon-Family.org> - 2018-03-09 13:16 -0500
                Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-09 21:33 +0200
                Re: Compile Assembly and C files together mm0fmf <none@invalid.com> - 2018-03-09 17:40 +0000
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 17:47 +0000
                Re: Compile Assembly and C files together mm0fmf <none@invalid.com> - 2018-03-09 18:05 +0000
                Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-09 09:05 +0000
                Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-09 16:01 +0200
            Re: Compile Assembly and C files together Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2018-03-08 17:25 +0200
    Re: Compile Assembly and C files together The Natural Philosopher <tnp@invalid.invalid> - 2018-03-07 07:36 +0000
  Re: Compile Assembly and C files together Richard Kettlewell <invalid@invalid.invalid> - 2018-03-06 15:29 +0000
    Re: Compile Assembly and C files together David Brown <david.brown@hesbynett.no> - 2018-03-06 16:38 +0100

csiph-web