public inbox for ecos-devel@sourceware.org
 help / color / mirror / Atom feed
* why use the SA1110-USB-driver a static /dev/usbs... definition ???
@ 2005-06-27 12:46 oliver munz @ s p e a g
  2005-06-27 13:02 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: oliver munz @ s p e a g @ 2005-06-27 12:46 UTC (permalink / raw)
  To: ecos-devel

Hello

I'm writing a device-driver on basis of the SA1110-USB-driver.
First I made a package without functionality. Then I tryed to get a handel
of my driver. It dosent worked. There was also no entry in the
..._install\lib\\libextras.a.

After houres of searching, I found, that the reason is the static definition
of the ..._devtab_entry. After removing the "static" key-word, my
test-program found his handels and does some pseudo inits...

The question for me is now, what is the reason for a static devtab?

The original source is:

"...\ecos\packages\devs\usb\sa11x0\current\src\usbs_sa11x0_data.cxx"

static CHAR_DEVIO_TABLE(usbs_sa11x0_ep0_devtab_functions,
    &cyg_devio_cwrite,
    &cyg_devio_cread,
    &cyg_devio_select,
    &usbs_devtab_get_config,
    &usbs_devtab_set_config);

static CHAR_DEVTAB_ENTRY(usbs_sa11x0_ep0_devtab_entry,
    CYGDAT_DEVS_USB_SA11X0_DEVTAB_BASENAME "0c",
    0,
    &usbs_sa11x0_ep0_devtab_functions,
    &usbs_sa11x0_devtab_ep0_init,
    0,
    (void*) &usbs_sa11x0_ep0);

Thanks for answers

Oliver Munz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why use the SA1110-USB-driver a static /dev/usbs... definition ???
  2005-06-27 12:46 why use the SA1110-USB-driver a static /dev/usbs... definition ??? oliver munz @ s p e a g
@ 2005-06-27 13:02 ` Andrew Lunn
  2005-06-27 13:41   ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2005-06-27 13:02 UTC (permalink / raw)
  To: oliver munz @ s p e a g; +Cc: ecos-devel

On Mon, Jun 27, 2005 at 02:46:23PM +0200, oliver munz @ s p e a g wrote:
> Hello
> 
> I'm writing a device-driver on basis of the SA1110-USB-driver.
> First I made a package without functionality. Then I tryed to get a handel
> of my driver. It dosent worked. There was also no entry in the
> ..._install\lib\\libextras.a.
> 
> After houres of searching, I found, that the reason is the static definition
> of the ..._devtab_entry. After removing the "static" key-word, my
> test-program found his handels and does some pseudo inits...
> 
> The question for me is now, what is the reason for a static devtab?
> 
> The original source is:
> 
> "...\ecos\packages\devs\usb\sa11x0\current\src\usbs_sa11x0_data.cxx"
> 
> static CHAR_DEVIO_TABLE(usbs_sa11x0_ep0_devtab_functions,
>    &cyg_devio_cwrite,
>    &cyg_devio_cread,
>    &cyg_devio_select,
>    &usbs_devtab_get_config,
>    &usbs_devtab_set_config);
> 
> static CHAR_DEVTAB_ENTRY(usbs_sa11x0_ep0_devtab_entry,
>    CYGDAT_DEVS_USB_SA11X0_DEVTAB_BASENAME "0c",
>    0,
>    &usbs_sa11x0_ep0_devtab_functions,
>    &usbs_sa11x0_devtab_ep0_init,
>    0,
>    (void*) &usbs_sa11x0_ep0);

This sounds like a garbage collection problem. Without the static the
variables the macros define will be global. So the compiler cannot
throw it away if its not referenced within the local file. If its
declared static and nothing references it within the file the compiler
has probably decided the variables are not needed and throw them
away. Hence they don't end up in libextras.a.

What version of gcc are you using? Something newish?

        Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why use the SA1110-USB-driver a static /dev/usbs... definition ???
  2005-06-27 13:02 ` Andrew Lunn
@ 2005-06-27 13:41   ` Andrew Lunn
  2005-06-27 14:34     ` oliver munz @ s p e a g
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2005-06-27 13:41 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: oliver munz @ s p e a g, ecos-devel

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

> What version of gcc are you using? Something newish?

My guess would be something like 3.4 or higher. 

http://www.gnu.org/software/gcc/gcc-3.4/changes.html

I says that "Unreferenced static variables and functions are removed"

This fits your problem description.

Please could you try the attached patch.

        Thanks
                Andrew


[-- Attachment #2: used.diff --]
[-- Type: text/plain, Size: 4012 bytes --]

Index: hal/common/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/common/current/ChangeLog,v
retrieving revision 1.109
diff -u -r1.109 ChangeLog
--- hal/common/current/ChangeLog	7 Jun 2005 18:31:35 -0000	1.109
+++ hal/common/current/ChangeLog	27 Jun 2005 13:40:04 -0000
@@ -1,3 +1,10 @@
+2005-06-27  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/hal_tables.h (CYG_HAL_TABLE_{QUALIFIED_}ENTRY): added
+	CYGBLD_ATTRIB_USED so that gcc 3.4.4 does not discard entries
+	which are not refereced explicitly. Problem reported by
+	Oliver Munz.
+	
 2005-05-19  Peter Korsgaard  <jacmet@sunsite.dk>
 
 	* doc/porting.sgml: Changed dead sourceware.cygnus.com links to
Index: hal/common/current/include/hal_tables.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/common/current/include/hal_tables.h,v
retrieving revision 1.7
diff -u -r1.7 hal_tables.h
--- hal/common/current/include/hal_tables.h	23 May 2002 23:02:47 -0000	1.7
+++ hal/common/current/include/hal_tables.h	27 Jun 2005 13:40:04 -0000
@@ -101,13 +101,15 @@
 
 #ifndef CYG_HAL_TABLE_ENTRY
 #define CYG_HAL_TABLE_ENTRY( _name ) \
-        CYGBLD_ATTRIB_SECTION(".ecos.table." __xstring(_name) ".data")
+        CYGBLD_ATTRIB_SECTION(".ecos.table." __xstring(_name) ".data") \
+        CYGBLD_ATTRIB_USED
 #endif
 
 #ifndef CYG_HAL_TABLE_QUALIFIED_ENTRY
 #define CYG_HAL_TABLE_QUALIFIED_ENTRY( _name, _qual ) \
         CYGBLD_ATTRIB_SECTION(".ecos.table." __xstring(_name) ".data." \
-                              __xstring(_qual))
+                              __xstring(_qual))                        \
+        CYGBLD_ATTRIB_USED
 #endif
 
 /*------------------------------------------------------------------------*/
Index: infra/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/ChangeLog,v
retrieving revision 1.49
diff -u -r1.49 ChangeLog
--- infra/current/ChangeLog	27 Mar 2005 18:14:58 -0000	1.49
+++ infra/current/ChangeLog	27 Jun 2005 13:40:05 -0000
@@ -1,3 +1,9 @@
+2005-06-27  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/cyg_type.h: Added CYGBLD_ATTRIB_USED so that we can
+	indicate to gcc 3.4.4 or above not to throw away a variable or
+	function even when it appears to be not references.
+	
 2005-03-27  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* include/diag.h: Added CYGBLD_ATTRIB_PRINTF_FORMAT where
Index: infra/current/include/cyg_type.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/infra/current/include/cyg_type.h,v
retrieving revision 1.22
diff -u -r1.22 cyg_type.h
--- infra/current/include/cyg_type.h	27 Mar 2005 18:14:59 -0000	1.22
+++ infra/current/include/cyg_type.h	27 Jun 2005 13:40:05 -0000
@@ -313,6 +313,15 @@
 // COMPILER-SPECIFIC STUFF
 
 #ifdef __GNUC__
+#if defined(__GNU_PATCHLEVEL__)
+# define __GNUC_VERSION__ (__GNUC__ * 10000 \
+                            + __GNUC_MINOR__ * 100 \
+                            + __GNUC_PATCHLEVEL__)
+#else
+# define __GNUC_VERSION__ (__GNUC__ * 10000 \
+                            + __GNUC_MINOR__ * 100)
+#endif
+
 // Force a 'C' routine to be called like a 'C++' contructor
 # if !defined(CYGBLD_ATTRIB_CONSTRUCTOR)
 #  define CYGBLD_ATTRIB_CONSTRUCTOR __attribute__((constructor))
@@ -383,6 +392,16 @@
 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__) \
         __attribute__((format (strftime, __format__, __args__)))
 
+// Tell the compiler not to throw away a variable or function. Only
+// available on 3.3.4 or above. Old version's didn't throw them away,
+// but using the unused attribute should stop warnings.
+# if !defined(CYGBLD_ATTRIB_USED)
+#  if __GNUC_VERSION__ >= 30404
+#   define CYGBLD_ATTRIB_USED __attribute__((used))
+#  else
+#   define CYGBLD_ATTRIB_USED __attribute__((unused))
+#  endif
+# endif 
 #else // non-GNU
 
 # define CYGBLD_ATTRIB_CONSTRUCTOR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why use the SA1110-USB-driver a static /dev/usbs... definition ???
  2005-06-27 13:41   ` Andrew Lunn
@ 2005-06-27 14:34     ` oliver munz @ s p e a g
  0 siblings, 0 replies; 4+ messages in thread
From: oliver munz @ s p e a g @ 2005-06-27 14:34 UTC (permalink / raw)
  To: Andrew Lunn, ecos-devel

Hi Andrew

You are right. I use an "arm-elf-gcc (GCC) 3.4.4"... I will try Your patch, 
when the driver is doing something.

If I understand the use of "static" in the USB-driver, then its only a 
matter of being not visible outside of the USB-driver. If the symbol will be 
in the library is controlled by the cdl-headers and compiler optimation is 
not usefull...

Thanks
Oli




----- Original Message ----- 
From: "Andrew Lunn" <andrew@lunn.ch>
To: "Andrew Lunn" <andrew@lunn.ch>
Cc: "oliver munz @ s p e a g" <munz@speag.ch>; 
<ecos-devel@sources.redhat.com>
Sent: Monday, June 27, 2005 3:40 PM
Subject: Re: why use the SA1110-USB-driver a static /dev/usbs... definition 
???


>> What version of gcc are you using? Something newish?
>
> My guess would be something like 3.4 or higher.
>
> http://www.gnu.org/software/gcc/gcc-3.4/changes.html
>
> I says that "Unreferenced static variables and functions are removed"
>
> This fits your problem description.
>
> Please could you try the attached patch.
>
>        Thanks
>                Andrew
>
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-27 14:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-27 12:46 why use the SA1110-USB-driver a static /dev/usbs... definition ??? oliver munz @ s p e a g
2005-06-27 13:02 ` Andrew Lunn
2005-06-27 13:41   ` Andrew Lunn
2005-06-27 14:34     ` oliver munz @ s p e a g

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).