public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* stripping symbols from modules
@ 2001-01-23 22:34 MEHTA,HIREN (A-SanJose,ex1)
  2001-01-23 23:06 ` Keith Owens
  2001-01-27 17:54 ` Willy Tarreau
  0 siblings, 2 replies; 7+ messages in thread
From: MEHTA,HIREN (A-SanJose,ex1) @ 2001-01-23 22:34 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org'

Hi All,

Is there any way to strip symbols from modules .o files ?
for example, fat.o has many symbols and when you run `file' command
on fat.o - it says that is is not a stripped file. 
I tried running `strip' command on fat.o and then tried to 
run insmod on the stripped fat.o and then tried to run
insmod on vfat.o. But the insmod on vfat.o generated the
"Unable to handle kernel NULL pointer dereference at virtual address
00000000" message. If there any way to remove symbols and still
load the module successfully and make it work ? Or the
problem is with the strip command ? Should I be using
something else instead of strip to remove symbols from
the module .o ?

I think, I am missing something. But I am not sure.

Thanks and regards,
-hiren
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: stripping symbols from modules
  2001-01-23 22:34 MEHTA,HIREN (A-SanJose,ex1)
@ 2001-01-23 23:06 ` Keith Owens
  2001-01-27 17:54 ` Willy Tarreau
  1 sibling, 0 replies; 7+ messages in thread
From: Keith Owens @ 2001-01-23 23:06 UTC (permalink / raw)
  To: MEHTA,HIREN (A-SanJose,ex1); +Cc: 'linux-kernel@vger.kernel.org'

On Tue, 23 Jan 2001 17:34:15 -0500, 
"MEHTA,HIREN (A-SanJose,ex1)" <hiren_mehta@agilent.com> wrote:
>Is there any way to strip symbols from modules .o files ?

Not safely.  Some symbols must be kept to assist insmod and hot
plugging, strip does not know about these special symbols.

Why do you need to strip modules anyway?  I don't see the point unless
you are critically low on disk space.  Stripping the symbols makes it
much harder to debug oops in modules, ksymoops needs all the symbols.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* RE: stripping symbols from modules
@ 2001-01-23 23:15 hiren_mehta
  2001-01-24  3:06 ` Keith Owens
  2001-01-24  7:42 ` H. Peter Anvin
  0 siblings, 2 replies; 7+ messages in thread
From: hiren_mehta @ 2001-01-23 23:15 UTC (permalink / raw)
  To: hiren_mehta; +Cc: linux-kernel

That is what I was guessing. But insmod does not need all symbols
present in the .o. 

I need to do this because when I release the driver to the customer,
I don't want them to be aware of some of the symbols. I understand
that this is against the open source policy. But that's how it is
and it is beyond my control. Is there any way to export only
selected symbols as required by insmod ? As of now I am not worried
about ksymoops.

Thanks and regards,
-hiren

> -----Original Message-----
> From: Keith Owens [mailto:kaos@ocs.com.au]
> Sent: Tuesday, January 23, 2001 3:06 PM
> To: MEHTA,HIREN (A-SanJose,ex1)
> Cc: 'linux-kernel@vger.kernel.org'
> Subject: Re: stripping symbols from modules 
> 
> 
> On Tue, 23 Jan 2001 17:34:15 -0500, 
> "MEHTA,HIREN (A-SanJose,ex1)" <hiren_mehta@agilent.com> wrote:
> >Is there any way to strip symbols from modules .o files ?
> 
> Not safely.  Some symbols must be kept to assist insmod and hot
> plugging, strip does not know about these special symbols.
> 
> Why do you need to strip modules anyway?  I don't see the point unless
> you are critically low on disk space.  Stripping the symbols makes it
> much harder to debug oops in modules, ksymoops needs all the symbols.
> 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: stripping symbols from modules
  2001-01-23 23:15 stripping symbols from modules hiren_mehta
@ 2001-01-24  3:06 ` Keith Owens
  2001-01-24  7:42 ` H. Peter Anvin
  1 sibling, 0 replies; 7+ messages in thread
From: Keith Owens @ 2001-01-24  3:06 UTC (permalink / raw)
  To: hiren_mehta; +Cc: linux-kernel

On Tue, 23 Jan 2001 16:15:24 -0700, 
hiren_mehta@agilent.com wrote:
>That is what I was guessing. But insmod does not need all symbols
>present in the .o. 
>
>I need to do this because when I release the driver to the customer,
>I don't want them to be aware of some of the symbols. I understand
>that this is against the open source policy. But that's how it is
>and it is beyond my control. Is there any way to export only
>selected symbols as required by insmod ? As of now I am not worried
>about ksymoops.

I used this script back in the dim distant days when emergency boot
systems had to fit on floppies.  Not tested since 1998, YMMV.  At the
very least it needs to be updated to keep MODULE_GENERIC_TABLE()
symbols.

#!/bin/sh
#
#	Given a list of objects, strip all static symbols except those
#	required by insmod.
#
#	Copyright Keith Owens <kaos@ocs.com.au>.  GPL.
#	Sat Feb  1 12:52:17 EST 1997
#	
#	Mainly intended for reducing the size of modules to save space
#	on emergency and install disks.  Be aware that removing the
#	static symbols reduces the amount of diagnostic information
#	available for oops.  Not recommended for normal module usage.
#
#	This code requires the modules use MODULE_PARM and EXPORT_.
#	Do not strip modules that have not been converted to use
#	MODULE_PARM or are using the old method of exporting symbols.
#	In particular do not use on modules prior to 2.1.20 (approx).
#
#	The objects are stripped in /tmp, only if the strip works is
#	the original overwritten.  If the command line to strip the
#	symbols becomes too long, the strip is done in multiple passes.
#	Running strip_module twice on the same object is safe (and a
#	waste of time).
#

cat > /tmp/$$.awk <<\EOF
BEGIN	{
	strip = "/usr/bin/objcopy";
	nm = "/usr/bin/nm";
	cp = "/bin/cp";
	mv = "/bin/mv";
	rm = "/bin/rm";
	tmp = "/tmp";
	command_size = 400;	# arbitrary but safe

	getline < "/proc/self/stat";
	pid = $1;
	tmpcopy = tmp "/" pid ".object";
	nmout = tmp "/" pid ".nmout";

	for (i = 1; i < ARGC; ++i)
		strip_module(ARGV[i]);

	do_command(rm " -f " tmpcopy " " nmout);

	exit(0);
}

function strip_module(object,
	keep_symbol, to_strip, symbol, command, changed) {
	do_command(cp " -a " object " " tmpcopy);
	do_command(nm " " tmpcopy " > " nmout);
	# delete array_name sometimes breaks, internal error, play safe
	for (symbol in keep_symbol)
		delete keep_symbol[symbol];
	for (symbol in to_strip)
		delete to_strip[symbol];
	new_module_format = 0;
	while ((getline < nmout) > 0) {
		$0 = substr($0, 10);
		# b static variable, uninitialised
		# d static variable, initialised
		# r static array, initialised
		# t static label/procedures
		if ($1 ~ /[bdrt]/)
			to_strip[$2] = "";
		else if ($1 != "?")
			keep_symbol[$2] = "";
		else if ($0 ~ /\? __ksymtab_/)
			keep_symbol[substr($2, 11)] = "";
		else if ($0 ~ /\? __module_parm_/)
			keep_symbol[substr($2, 15)] = "";
		if ($0 ~ /\? __module/)
			new_module_format = 1;
	}
	close(nmout);
	command = "";
	changed = 0;
	if (new_module_format) {
		for (symbol in to_strip) {
			if (!(symbol in keep_symbol)) {
				changed = 1;
				if (length(command) > command_size) {
					do_command(strip command " " tmpcopy);
					command = "";
				}
				command = command " --strip-symbol=" symbol;
			}
		}
	}
	if (command != "") {
		changed = 1;
		do_command(strip command " " tmpcopy);
	}
	if (changed)
		do_command(mv " " tmpcopy " " object);
}

function do_command(command) {
	if ((ret = system(command)) != 0)
		giveup("command \"" command "\" failed " ret, ret);
}

function giveup(message, ret) {
	print "strip_module: " message > "/dev/stderr";
	exit(ret);
}
EOF

awk -f /tmp/$$.awk "$@"
ret=$?
rm -f /tmp/$$.awk
exit $ret

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: stripping symbols from modules
  2001-01-23 23:15 stripping symbols from modules hiren_mehta
  2001-01-24  3:06 ` Keith Owens
@ 2001-01-24  7:42 ` H. Peter Anvin
  2001-01-24 18:36   ` Paul Gortmaker
  1 sibling, 1 reply; 7+ messages in thread
From: H. Peter Anvin @ 2001-01-24  7:42 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <FEEBE78C8360D411ACFD00D0B747797188095D@xsj02.sjs.agilent.com>
By author:    hiren_mehta@agilent.com
In newsgroup: linux.dev.kernel
>
> That is what I was guessing. But insmod does not need all symbols
> present in the .o. 
> 
> I need to do this because when I release the driver to the customer,
> I don't want them to be aware of some of the symbols. I understand
> that this is against the open source policy. But that's how it is
> and it is beyond my control. Is there any way to export only
> selected symbols as required by insmod ? As of now I am not worried
> about ksymoops.
> 

I think "strip --strip-unneeded" is what you want.

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: stripping symbols from modules
  2001-01-24  7:42 ` H. Peter Anvin
@ 2001-01-24 18:36   ` Paul Gortmaker
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Gortmaker @ 2001-01-24 18:36 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

H. Peter Anvin wrote:

>Is there any way to export only
> > selected symbols as required by insmod ? As of now I am not worried
> > about ksymoops.
> >
> 
> I think "strip --strip-unneeded" is what you want.
> 

I think you will find "--strip-unneeded" will toss out init_module
and cleanup_module (and perhaps others). Using "strip -g -x ..."
would leave the important bits in place IIRC (at least on 2.2.x).

Paul.



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: stripping symbols from modules
  2001-01-23 22:34 MEHTA,HIREN (A-SanJose,ex1)
  2001-01-23 23:06 ` Keith Owens
@ 2001-01-27 17:54 ` Willy Tarreau
  1 sibling, 0 replies; 7+ messages in thread
From: Willy Tarreau @ 2001-01-27 17:54 UTC (permalink / raw)
  To: MEHTA,HIREN (A-SanJose,ex1); +Cc: 'linux-kernel@vger.kernel.org'

Hi !

> Is there any way to strip symbols from modules .o files ?

there are many symbols you have to keep. You also have to keep modules args
and exported modules. I personnaly use this method which seems to work OK even
if it's really awful (although I'm not sure it will work under all
circumstances) :

for i in *.o; do
       objcopy -R __ksymtab -R .comment -R .note -x `nm $i |
          grep ' ? \(__module_parm_\)\|\(__ks..tab_\)' |
          sed -e 's/\(__module_parm_\)\(.*\)/\2/'
              -e 's/\(__ks..tab_\)\(.*\)/\2/' | cut -f3- -d' ' | sort -u |
          awk '{printf " -K "$1}'` $i
done


After this, I even compress the modules because you can often gain about a 2.5
ratio.

Cheers,
Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

end of thread, other threads:[~2001-01-27 17:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-23 23:15 stripping symbols from modules hiren_mehta
2001-01-24  3:06 ` Keith Owens
2001-01-24  7:42 ` H. Peter Anvin
2001-01-24 18:36   ` Paul Gortmaker
  -- strict thread matches above, loose matches on Subject: below --
2001-01-23 22:34 MEHTA,HIREN (A-SanJose,ex1)
2001-01-23 23:06 ` Keith Owens
2001-01-27 17:54 ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox