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

RE: [rtl] Problem loading modules



One more thought on this.  The traditional usual cure to avoid the copy on
entry is to write:
	static	 char buf[12] = "test";  
which (possibly architecture- and compiler-dependent) usually creates a
static array with no copy operation performed.

	Norm

>From: "Dresner, Norman A." <norman_a_dresner@md.northgrum.com>
>To: "'Stuart Hughes'" <sehughes@zentropix.com>
>Cc: "'RTLinux'" <rtl@rtlinux.org>
>Subject: RE: [rtl] Problem loading modules
>Date: Thu, 24 Feb 2000 12:59:32 -0500
>X-Mailer: Internet Mail Service (5.5.2448.0)
>Sender: owner-rtl@fsmlabs.com
>
>> -----Original Message-----
>> From:	Stuart Hughes [SMTP:sehughes@zentropix.com]
>> Sent:	Wednesday, February 23, 2000 6:39 AM
>> To:	David Schleef
>> Cc:	rtlinux
>> Subject:	Re: [rtl] Problem loading modules
>> 
>> David Schleef wrote:
>> > 
>> > On Tue, Feb 22, 2000 at 12:51:11PM +0000, Stuart Hughes wrote:
>> > >
>> > > Note also the following compiler feature:
>> > >
>> > > If have in your RT code:
>> > >
>> > >       char buf[12] = "mystring";
>> > >
>> > > You get an error, due to an implicit call to memset.
>> > 
>> > Nope.  gcc-2.7.2.3 outputs assembly instructions that perform
>> > the memcpy, even with very long strings.
>> 
>> Hi Dave, 
>> 
>> That's weird, this is what I get (gcc version 2.7.2.3).  If I compile
>> the code below using:
>> 
>> cc -O2 -g -D__KERNEL__ -DMODULE -c -o para_mod.o para.c
>> 
>> and then try to insmod para_mod.o, I get the following:
>> 
>> ./para_mod.o: unresolved symbol memset
>> 
>> If I comment out the first version and uncomment the second, everything
>> works ???
>> 
>> Any ideas ??
>> 
>	[Norm Says:]  
>	The first form ( char buff[12]="test"; ) creates the string "test"
>somewhere in memory and then when the function init_module is entered, space
>is made on the stack for the buf[] array and the string is copied from the
>string to the array.
>
>	The second form ( char *buff="test";) also creates the string "test"
>in memory -- probably in the same place as the first -- but when the
>function init_module is entered, just the space for a char-pointer is made
>on the stack and the pointer is initialized with the addess of the string;
>no copying is done, just the storing of a "numeric" data item on the stack
>(possibly even a push of immediate data).
>
>	It's all perfectly logical.
>
>		Norm
>
>> Regards, Stuart
>> 
>> 
>> // System headers.
>> #include <linux/module.h>
>> #include <asm/io.h>
>> 
>> int init_module(void)
>> {
>>     char buf[12] = "test";              // fails, calls implicit memset
>> //    char *buf = "test";               // Okay
>>     printk(buf);
>> 
>>     return 0;
>> }
>> 
>> void cleanup_module(void)
>> {
>> }
>> 
>> 
>> -- [rtl] ---
>> To unsubscribe:
>> echo "unsubscribe rtl" | mail majordomo@rtlinux.org OR
>> echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.org
>> ---
>> For more information on Real-Time Linux see:
>> http://www.rtlinux.org/~rtlinux/
>-- [rtl] ---
>To unsubscribe:
>echo "unsubscribe rtl" | mail majordomo@rtlinux.org OR
>echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.org
>---
>For more information on Real-Time Linux see:
>http://www.rtlinux.org/~rtlinux/
>
>