Re: [rtl] Problem loading modules

2000-02-25 Thread Kulwinder Atwal

"Dresner, Norman A." wrote:
> 
> > -Original Message-
> > From: Stuart Hughes [SMTP:[EMAIL PROTECTED]]
> > 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 +, 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
> 

Not just logical, but the second form is also preferable.  Passing by
reference should be encouraged, whenever possible, instead of passing by
value due to its greater memory and speed efficiency. Also, if you are
going to be hard coding strings, using a 'const' pointer will be safer.

const char *buff = "test";

- Cheers, Kal.


> > Regards, Stuart
> >
> >
> > // System headers.
> > #include 
> > #include 
> >
> > 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 [EMAIL PROTECTED] OR
> > echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
> > ---
> > For more information on Real-Time Linux see:
> > http://www.rtlinux.org/~rtlinux/
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/~rtlinux/
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



RE: [rtl] Problem loading modules

2000-02-24 Thread Norm Dresner

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." <[EMAIL PROTECTED]>
>To: "'Stuart Hughes'" <[EMAIL PROTECTED]>
>Cc: "'RTLinux'" <[EMAIL PROTECTED]>
>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: [EMAIL PROTECTED]
>
>> -Original Message-
>> From:Stuart Hughes [SMTP:[EMAIL PROTECTED]]
>> 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 +, 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 
>> #include 
>> 
>> 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 [EMAIL PROTECTED] OR
>> echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
>> ---
>> For more information on Real-Time Linux see:
>> http://www.rtlinux.org/~rtlinux/
>-- [rtl] ---
>To unsubscribe:
>echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
>echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
>---
>For more information on Real-Time Linux see:
>http://www.rtlinux.org/~rtlinux/
>
>
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



RE: [rtl] Problem loading modules

2000-02-24 Thread Dresner, Norman A.

> -Original Message-
> From: Stuart Hughes [SMTP:[EMAIL PROTECTED]]
> 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 +, 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 
> #include 
> 
> 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 [EMAIL PROTECTED] OR
> echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/~rtlinux/
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-24 Thread Stuart Hughes

David Schleef wrote:
> 
> On Tue, Feb 22, 2000 at 12:51:11PM +, 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 ??

Regards, Stuart


// System headers.
#include 
#include 

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 [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-23 Thread David Schleef

On Wed, Feb 23, 2000 at 11:04:35AM +0100, Erwin Authried wrote:
> David Schleef[SMTP:[EMAIL PROTECTED]] wrote:
> > 
> > Nope.  gcc-2.7.2.3 outputs assembly instructions that perform
> > the memcpy, even with very long strings.
> > 
> > 
> > 
> > dave...
> > 
> Be careful. With *exactly* the statement above, compiled with -O2,  memset is called.
> With some shorter or longer strings, memset is not used. 
> 
> -erwin
>  


You are correct.  I somehow managed to completely ignore "memset" and
focused instead on my incorrect interpretation of "memset" as "memcpy".

I'm happy you corrected me, because this brings up gcc bugs/features
(depending on perspective) on multiple levels.

On one level, gcc optimization is _definiately_ wrong calling
memset(ptr,0,3) instead of the trivial two or three instructions
required to zero by hand.  This appears to be the behavior in both
gcc-2.7.2.3 and egcs-2.91.66.  This deserves a bug report.

Then, of course, it is not clear that gcc should be calling library
functions instead of __builtin_memset or just inlining memset code,
especially when the -fno-builtins flag is set.  It is true that
memset can have no other legitimate meaning.  But clearly, for the
purposes here, generating "call memset" is not useful, and in other
circumstances, "call memset" is definately bad.

Grepping the gcc source indicates that there are a number of function
calls that gcc will emit in certain circumstances.




dave...


-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-23 Thread Paul Koning

> "David" == David Schleef <[EMAIL PROTECTED]> writes:

 David> On Tue, Feb 22, 2000 at 12:51:11PM +, 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.


 David> Nope.  gcc-2.7.2.3 outputs assembly instructions that perform
 David> the memcpy, even with very long strings.

Note that's an x86 specific statement.  Other platforms may have
different properties.

paul
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-23 Thread Erwin Authried

David Schleef[SMTP:[EMAIL PROTECTED]] wrote:
> On Tue, Feb 22, 2000 at 12:51:11PM +, 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.
> 
> 
> 
> dave...
> 
Be careful. With *exactly* the statement above, compiled with -O2,  memset is called.
With some shorter or longer strings, memset is not used. 

-erwin
 

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-22 Thread David Schleef

On Tue, Feb 22, 2000 at 12:51:11PM +, 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.



dave...

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-22 Thread Stuart Hughes

Giorgio Lami wrote:
> 
> Hi,
> 
> I've some problems using strings in a module.
> 
> When I try to load a module where I've used the function strcat ("string.h")
> or the function pow ("math.h") I get the error message "unresolved symbol
> strcat" (or "unresolved symbol function pow).
> 
> How can I do?

Hi Giorgio,

You need to do a:

#include 

and compile with -O2 to pull in the in-line function


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.

If instead you put:

char *buf = "mystring";

It should work fine.

Regards, Stuart
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-18 Thread David Schleef

On Fri, Feb 18, 2000 at 04:12:22AM -0700, Kulwinder Atwal wrote:
> Paul Koning wrote:
> > 
> > > "Dresner," == Dresner, Norman A <[EMAIL PROTECTED]> writes:
> > 
> >  Dresner,> It has to be possible to "re-create" functions like strcat
> >  Dresner,> et al that are usable in the kernel, and I have difficulty
> >  Dresner,> believing that someone hasn't already done just that.
> > 
> > You don't need to re-create anything.  All you need is to link the
> > relevant object library with your module.
> > 
> > That assumes, of course, that the library doesn't need to do system
> > calls (like malloc).  For example, the strings stuff should be fine
> > except for "strstr".  Math should be fine unless there's some
> > exception related stuff in it.
> 
> Use the functions in include/asm-i386/string-486.h
> Although the call 'strstr' does not appear in string.h it is in this
> file.

You may wish to use  instead, since it will do the right
thing on different processors.



dave...

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-18 Thread Paul Koning

> "Kulwinder" == Kulwinder Atwal <[EMAIL PROTECTED]> writes:

 Kulwinder> Paul Koning wrote:
 >>  > "Dresner," == Dresner, Norman A
 >> <[EMAIL PROTECTED]> writes:
 >> 
 >> Dresner,> It has to be possible to "re-create" functions like
 >> strcat Dresner,> et al that are usable in the kernel, and I have
 >> difficulty Dresner,> believing that someone hasn't already done
 >> just that.
 >> 
 >> You don't need to re-create anything.  All you need is to link the
 >> relevant object library with your module.
 >> 
 >> That assumes, of course, that the library doesn't need to do
 >> system calls (like malloc).  For example, the strings stuff should
 >> be fine except for "strstr".  Math should be fine unless there's
 >> some exception related stuff in it.

 Kulwinder> Use the functions in include/asm-i386/string-486.h
 Kulwinder> Although the call 'strstr' does not appear in string.h it
 Kulwinder> is in this file.

Oops, I meant "strdup" as one likely to cause trouble.  There's
nothing about "strstr" that suggests you can't use it in an RTL.

I don't know why (other than performance) it's important to use asm
versions... the C versions should be pure functions just as much as
the asm versions.

paul
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



Re: [rtl] Problem loading modules

2000-02-18 Thread Kulwinder Atwal

Paul Koning wrote:
> 
> > "Dresner," == Dresner, Norman A <[EMAIL PROTECTED]> writes:
> 
>  Dresner,> It has to be possible to "re-create" functions like strcat
>  Dresner,> et al that are usable in the kernel, and I have difficulty
>  Dresner,> believing that someone hasn't already done just that.
> 
> You don't need to re-create anything.  All you need is to link the
> relevant object library with your module.
> 
> That assumes, of course, that the library doesn't need to do system
> calls (like malloc).  For example, the strings stuff should be fine
> except for "strstr".  Math should be fine unless there's some
> exception related stuff in it.

Use the functions in include/asm-i386/string-486.h
Although the call 'strstr' does not appear in string.h it is in this
file.

These functions are written in 486 assembly code and thus completely
independent of Linux.  That is if you are using a 486 or better.  If you
are using a different architecture look for a similar file in your asm
directory to see if 'strstr' is supported.

- Kal.

> 
>  >> you cannot use standard library functions in your modules.
> 
> That's not true.  It's true for libraries that use Linux system
> services; for libraries that are just self-contained functions, there
> is no problem.
> 
>  >> You
>  >> can use functions of your own or ones provided by kernel (man
>  >> ksyms). On this mailing list, it was mentioned that it's possible
>  >> to use math functions (-lm) in the modules.
> 
> Right...
> 
> paul
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/~rtlinux/
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/



RE: [rtl] Problem loading modules

2000-02-16 Thread Paul Koning

> "Dresner," == Dresner, Norman A <[EMAIL PROTECTED]> writes:

 Dresner,> It has to be possible to "re-create" functions like strcat
 Dresner,> et al that are usable in the kernel, and I have difficulty
 Dresner,> believing that someone hasn't already done just that.

You don't need to re-create anything.  All you need is to link the
relevant object library with your module.

That assumes, of course, that the library doesn't need to do system
calls (like malloc).  For example, the strings stuff should be fine
except for "strstr".  Math should be fine unless there's some
exception related stuff in it.

 >> you cannot use standard library functions in your modules.  

That's not true.  It's true for libraries that use Linux system
services; for libraries that are just self-contained functions, there
is no problem.

 >> You
 >> can use functions of your own or ones provided by kernel (man
 >> ksyms). On this mailing list, it was mentioned that it's possible
 >> to use math functions (-lm) in the modules.

Right...

paul
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl " | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/