From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IrHUj-0000na-0Z for mharc-grub-devel@gnu.org; Sun, 11 Nov 2007 13:25:17 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IrHUg-0000mo-TU for grub-devel@gnu.org; Sun, 11 Nov 2007 13:25:15 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IrHUf-0000mD-Lr for grub-devel@gnu.org; Sun, 11 Nov 2007 13:25:14 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IrHUf-0000mA-B9 for grub-devel@gnu.org; Sun, 11 Nov 2007 13:25:13 -0500 Received: from mailout05.sul.t-online.de ([194.25.134.82] helo=mailout05.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IrHUe-0005Si-RC for grub-devel@gnu.org; Sun, 11 Nov 2007 13:25:13 -0500 Received: from fwd31.aul.t-online.de by mailout05.sul.t-online.com with smtp id 1IrHUb-00085P-05; Sun, 11 Nov 2007 19:25:09 +0100 Received: from [10.3.2.2] (VgKZX-ZErhTvfTrF1wH4c+ehRE6shUOGUK-yCLPe4yqssmuloplGAbnETRL1YRTwFx@[217.235.197.117]) by fwd31.aul.t-online.de with esmtp id 1IrHUK-1zpVUe0; Sun, 11 Nov 2007 19:24:52 +0100 Message-ID: <473748F4.4070206@t-online.de> Date: Sun, 11 Nov 2007 19:24:52 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: The development of GRUB 2 References: <4736009D.3010502@t-online.de> <20071110212421.GI15633@thorin> In-Reply-To: <20071110212421.GI15633@thorin> Content-Type: multipart/mixed; boundary="------------050509020102080607050604" X-ID: VgKZX-ZErhTvfTrF1wH4c+ehRE6shUOGUK-yCLPe4yqssmuloplGAbnETRL1YRTwFx X-TOI-MSGID: 4481d03b-eb8d-451c-9325-57483ce745bf X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] Handle C symbols with leading underscore (HAVE_ASM_USCORE) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Nov 2007 18:25:15 -0000 This is a multi-part message in MIME format. --------------050509020102080607050604 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Robert Millan wrote: > On Sat, Nov 10, 2007 at 08:03:57PM +0100, Christian Franke wrote: > >> This patch fixes this by ignoring the difference. It actually works to >> load modules compiled on Linux by a kernel compiled on Cygwin (with >> underscores) and vice versa. >> >> [...] >> + >> + /* Ignore leading underscore used for C symbols. >> + Done at runtime to allow loading modules compiled on other OS. */ >> + if (*name == '_') >> + name++; >> > > Is that something we really want? We never made any efforts at maintaining > ABI between kernel and modules, or in allowing this kind of combinations. If > we go this path, it can mean more work later (e.g. support for building kernel > and modules with different versions of GCC, etc). > > Agree. Should the kernel probably check whether a module is build for the same target? This would avoid interesting behaviour if a foreign module is accidentally load for some reason. It could e.g. be done by checking a symbol derived from $target. > Could you give an example of a situation in which this would be useful? > > There probably is none, therefore the (older) patch for the other variant is attached :-) Christian 2007-11-11 Christian Franke * genkernsyms.sh.in: Handle HAVE_ASM_USCORE case. * genmk.rb: Handle HAVE_ASM_USCORE case in strip command. Add EXEEXT to CLEANFILES. * gensymlist.sh.in: Handle HAVE_ASM_USCORE case. * kern/dl.c (grub_dl_resolve_symbols): Add check for grub_mod_init and grub_mod_fini for symbols without a type. Handle HAVE_ASM_USCORE case for these symbols. (grub_dl_resolve_dependencies): Add check for trailing nullbytes in symbol table. This fixes an infinite loop if table is zero filled. --------------050509020102080607050604 Content-Type: text/x-patch; name="grub2-asm_uscore-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-asm_uscore-2.patch" diff -rup grub2.orig/genkernsyms.sh.in grub2/genkernsyms.sh.in --- grub2.orig/genkernsyms.sh.in 2006-07-12 22:42:52.000000000 +0200 +++ grub2/genkernsyms.sh.in 2007-10-06 12:59:29.000000000 +0200 @@ -16,9 +16,12 @@ srcdir=@srcdir@ CC="@CC@" +u= +grep "^#define HAVE_ASM_USCORE" config.h >/dev/null 2>&1 && u="_" + $CC -DGRUB_SYMBOL_GENERATOR=1 -E -I. -Iinclude -I$srcdir/include $* \ | grep -v '^#' \ | sed -n \ - -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/\1 kernel/;p;}' \ - -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/\1 kernel/;p;}' \ + -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/'"$u"'\1 kernel/;p;}' \ + -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/'"$u"'\1 kernel/;p;}' \ | sort -u diff -rup grub2.orig/genmk.rb grub2/genmk.rb --- grub2.orig/genmk.rb 2007-10-20 22:49:38.968750000 +0200 +++ grub2/genmk.rb 2007-11-10 19:37:17.562500000 +0100 @@ -115,7 +115,7 @@ UNDSYMFILES += #{undsym} #{@name}: #{pre_obj} #{mod_obj} -rm -f $@ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ - $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ + $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} -rm -f $@ @@ -187,7 +187,7 @@ class Utility deps = objs.collect {|obj| obj.suffix('d')} deps_str = deps.join(' '); - "CLEANFILES += #{@name} #{objs_str} + "CLEANFILES += #{@name}$(EXEEXT) #{objs_str} MOSTLYCLEANFILES += #{deps_str} #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} diff -rup grub2.orig/gensymlist.sh.in grub2/gensymlist.sh.in --- grub2.orig/gensymlist.sh.in 2007-07-22 01:32:18.000000000 +0200 +++ grub2/gensymlist.sh.in 2007-10-07 17:47:37.000000000 +0200 @@ -16,6 +16,8 @@ srcdir=@srcdir@ CC=@CC@ +u= +grep "^#define HAVE_ASM_USCORE" config.h >/dev/null 2>&1 && u="_" cat <st_info); unsigned char bind = ELF_ST_BIND (sym->st_info); const char *name = str + sym->st_name; + int check_mod_func = 0; switch (type) { @@ -359,6 +366,12 @@ grub_dl_resolve_symbols (grub_dl_t mod, return grub_error (GRUB_ERR_BAD_MODULE, "the symbol `%s' not found", name); } + else if (sym->st_name != 0 && bind == STB_LOCAL) + { /* Static functions have no type if initial format was not ELF. */ + sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, + sym->st_shndx); + check_mod_func = 1; + } else sym->st_value = 0; break; @@ -374,14 +387,11 @@ grub_dl_resolve_symbols (grub_dl_t mod, case STT_FUNC: sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, sym->st_shndx); - if (bind != STB_LOCAL) + if (bind == STB_LOCAL) + check_mod_func = 1; + else if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) return grub_errno; - - if (grub_strcmp (name, "grub_mod_init") == 0) - mod->init = (void (*) (grub_dl_t)) sym->st_value; - else if (grub_strcmp (name, "grub_mod_fini") == 0) - mod->fini = (void (*) (void)) sym->st_value; break; case STT_SECTION: @@ -397,6 +407,13 @@ grub_dl_resolve_symbols (grub_dl_t mod, return grub_error (GRUB_ERR_BAD_MODULE, "unknown symbol type `%d'", (int) type); } + if (check_mod_func) + { + if (grub_strcmp (name, SYM_USCORE "grub_mod_init") == 0) + mod->init = (void (*) (grub_dl_t)) sym->st_value; + else if (grub_strcmp (name, SYM_USCORE "grub_mod_fini") == 0) + mod->fini = (void (*) (void)) sym->st_value; + } } return GRUB_ERR_NONE; @@ -454,7 +471,7 @@ grub_dl_resolve_dependencies (grub_dl_t const char *name = (char *) e + s->sh_offset; const char *max = name + s->sh_size; - while (name < max) + while (name < max && *name) /* Segment may contain trailing 0. */ { grub_dl_t m; grub_dl_dep_t dep; --------------050509020102080607050604--