From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,2afd440a210c7fb0 X-Google-Attributes: gidf7344,public X-Google-Thread: 1014db,6bdc5c27a0dec527 X-Google-Attributes: gid1014db,public X-Google-Thread: 1164f8,df8a3dc583bf1f5f X-Google-Attributes: gid1164f8,public From: torek@elf.bsdi.com (Chris Torek) Subject: Re: Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA * Date: 1998/08/30 Message-ID: <6scnqc$ilb@elf.bsdi.com>#1/1 X-Deja-AN: 386272982 References: <0095000017115526000002L062*@MHS> <6sac4v$4ti$1@Starbase.NeoSoft.COM> <35e8f9d7.0@news.wizvax.net> <35E9DAA0.8097B24F@videotron.ca> X-Complaints-To: abuse@cs.umd.edu X-Trace: cronkite.cs.umd.edu 904520525 18312 205.230.228.129 (30 Aug 1998 23:42:05 GMT) Organization: none of the above NNTP-Posting-Date: 30 Aug 1998 23:42:05 GMT Newsgroups: comp.os.vms,comp.sys.dec,comp.lang.c In article <35E9DAA0.8097B24F@videotron.ca> JF Mezei wrote: >There is no difference between a library call and a user-written >function. I once worked on a project where a hacker had created >his own libraries that redefined all the standard C routines ... No difference? % cat >foo.c #include void *memory_copy(void *dst, const void *src, size_t len); void f1(int *dst, int *src) { memcpy(dst, src, sizeof *dst); } void f2(int *dst, int *src) { memory_copy(dst, src, sizeof *dst); } % cc -S -O2 foo.c -fomit-frame-pointer .file "foo.c" .version "01.01" gcc2_compiled.: .text .align 4 .globl f1 .type f1,@function f1: movl 4(%esp),%eax movl 8(%esp),%edx movl (%edx),%edx movl %edx,(%eax) ret .Lfe1: .size f1,.Lfe1-f1 .align 4 .globl f2 .type f2,@function f2: pushl $4 pushl 12(%esp) pushl 12(%esp) call memory_copy addl $12,%esp ret .Lfe2: .size f2,.Lfe2-f2 .ident "GCC: (GNU) 2.7.2.1" % If there is no difference between a call to memcpy and a call to memory_copy, why is it that f2() contains a call, but f1() does not? And if I did attempt to subvert memcpy(), when would my memcpy() get called, vs the implementation's? Does this compiler inline calls to printf() in the same way it inlines calls to memcpy()? How do you know? (*I* know, because I have to work on this compiler now and then. You could obtain the source for GCC 2.7.2.1 and read it, but how will you know what changes I may have made?) -- In-Real-Life: Chris Torek, Berkeley Software Design Inc El Cerrito, CA Domain: torek@bsdi.com +1 510 234 3167 Antispam notice: unsolicited commercial email will be handled at my consulting rate; pyramid-scheme mail will be forwarded to the FTC.