* [PATCH 1/3] Improve genmoddep.awk
@ 2009-07-01 0:35 Pavel Roskin
2009-07-01 0:35 ` [PATCH 2/3] Don't put modules without dependencies into moddep.lst Pavel Roskin
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 0:35 UTC (permalink / raw)
To: grub-devel
Avoid pipeline in its invocation. It's hard to get the result of a
pipeline reliably. Eliminate the need in "und-*" files by caching and
postprocessing undefined symbols.
ChangeLog:
* Makefile.in: Invoke genmoddep.awk without any pipelines.
Eliminate UNDSYMFILES.
* genmk.rb: Write undefined symbols to the same files as defined
symbols.
* genmoddep.awk: Process only files from the command line,
recognize defined symbols by the number of records. Save
undefined symbols in a table, process them later. Output to the
file specified by the MODDEP environment variable. Report all
undefined symbols.
---
Makefile.in | 6 ++----
genmk.rb | 17 ++++++-----------
genmoddep.awk | 39 ++++++++++++++++++++++++---------------
3 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index f82566a..e6be9c4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -148,10 +148,8 @@ include $(srcdir)/conf/$(target_cpu)-$(platform).mk
CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA)
pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst
-moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk
- cat $(DEFSYMFILES) /dev/null \
- | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \
- || (rm -f $@; exit 1)
+moddep.lst: $(DEFSYMFILES) genmoddep.awk
+ MODDEP=$@ $(AWK) -f $(srcdir)/genmoddep.awk $(DEFSYMFILES)
command.lst: $(COMMANDFILES)
cat $^ /dev/null | sort > $@
diff --git a/genmk.rb b/genmk.rb
index e3866c1..2883362 100644
--- a/genmk.rb
+++ b/genmk.rb
@@ -110,17 +110,15 @@ class PModule
mod_src = 'mod-' + @name.suffix('c')
mod_obj = mod_src.suffix('o')
defsym = 'def-' + @name.suffix('lst')
- undsym = 'und-' + @name.suffix('lst')
mod_name = File.basename(@name, '.mod')
symbolic_name = mod_name.sub(/\.[^\.]*$/, '')
- "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym}
+ "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str}
ifneq ($(#{prefix}_EXPORTS),no)
CLEANFILES += #{defsym}
DEFSYMFILES += #{defsym}
endif
MOSTLYCLEANFILES += #{deps_str}
-UNDSYMFILES += #{undsym}
ifneq ($(TARGET_APPLE_CC),1)
#{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF)
@@ -148,19 +146,16 @@ endif
sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
ifneq ($(#{prefix}_EXPORTS),no)
-ifneq ($(TARGET_APPLE_CC),1)
#{defsym}: #{pre_obj}
- $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+ echo '#{mod_name}' > $@
+ $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
+ifneq ($(TARGET_APPLE_CC),1)
+ $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' >> $@
else
-#{defsym}: #{pre_obj}
- $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
+ $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' >> $@
endif
endif
-#{undsym}: #{pre_obj}
- echo '#{mod_name}' > $@
- $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
-
" + objs.collect_with_index do |obj, i|
src = sources[i]
fake_obj = File.basename(src).suffix('o')
diff --git a/genmoddep.awk b/genmoddep.awk
index f7f085e..db8e07e 100644
--- a/genmoddep.awk
+++ b/genmoddep.awk
@@ -11,11 +11,14 @@
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
-# Read defined symbols from stdin.
-BEGIN {
- while (getline <"/dev/stdin") {
- symtab[$1] = $2
- }
+# This program processes lists of defined and undefined symbols given on
+# the command line. The output filename is determined by the MODDEP
+# environment variable.
+
+# Each defined symbol is followed by the module name.
+NF == 2 {
+ symtab[$1] = $2
+ next
}
# The first line contains a module name.
@@ -25,19 +28,25 @@ FNR == 1 {
};
# The rest is undefined symbols.
-{
- if ($1 in symtab) {
- modtab[module] = modtab[module] " " symtab[$1];
- }
- else {
- printf "%s in %s is not defined\n", $1, module >"/dev/stderr";
- error++;
- exit;
- }
+NF == 1 {
+ undtab[$1] = undtab[$1] " " module
}
# Output the result.
END {
+ for (sym in undtab) {
+ if (sym in symtab) {
+ split(undtab[sym], mods, " ");
+ for (i in mods) {
+ modtab[mods[i]] = modtab[mods[i]] " " symtab[sym];
+ }
+ }
+ else {
+ printf "Symbol \"%s\" is not defined in modules:%s\n", sym, undtab[sym] >"/dev/stderr";
+ error = 1;
+ }
+ }
+
if (error == 1)
exit 1;
@@ -57,6 +66,6 @@ END {
for (depmod in uniqmods) {
modlist = modlist " " depmod;
}
- printf "%s:%s\n", mod, modlist;
+ printf "%s:%s\n", mod, modlist >ENVIRON["MODDEP"];
}
}
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] Don't put modules without dependencies into moddep.lst
2009-07-01 0:35 [PATCH 1/3] Improve genmoddep.awk Pavel Roskin
@ 2009-07-01 0:35 ` Pavel Roskin
2009-07-01 13:10 ` Robert Millan
2009-07-01 0:35 ` [PATCH 3/3] Use ELF symbols without "32" or "64" Pavel Roskin
2009-07-01 3:44 ` [PATCH 1/3] Improve genmoddep.awk Bean
2 siblings, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 0:35 UTC (permalink / raw)
To: grub-devel
ChangeLog:
* genmoddep.awk: Don't output lines that contain to
dependencies.
---
genmoddep.awk | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/genmoddep.awk b/genmoddep.awk
index db8e07e..1bdf7f1 100644
--- a/genmoddep.awk
+++ b/genmoddep.awk
@@ -66,6 +66,8 @@ END {
for (depmod in uniqmods) {
modlist = modlist " " depmod;
}
- printf "%s:%s\n", mod, modlist >ENVIRON["MODDEP"];
+ if (modlist != "") {
+ printf "%s:%s\n", mod, modlist >ENVIRON["MODDEP"];
+ }
}
}
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] Use ELF symbols without "32" or "64"
2009-07-01 0:35 [PATCH 1/3] Improve genmoddep.awk Pavel Roskin
2009-07-01 0:35 ` [PATCH 2/3] Don't put modules without dependencies into moddep.lst Pavel Roskin
@ 2009-07-01 0:35 ` Pavel Roskin
2009-07-01 3:44 ` [PATCH 1/3] Improve genmoddep.awk Bean
2 siblings, 0 replies; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 0:35 UTC (permalink / raw)
To: grub-devel
ChangeLog:
* include/grub/elf.h: Define Elf_Sword and Elf_Xword.
* kern/i386/dl.c: Use ELF symbols without "32" or "64".
* kern/powerpc/dl.c: Likewise.
* kern/sparc64/dl.c: Likewise.
* kern/x86_64/dl.c: Likewise.
---
include/grub/elf.h | 4 ++++
kern/i386/dl.c | 34 +++++++++++++++++-----------------
kern/powerpc/dl.c | 42 +++++++++++++++++++++---------------------
kern/sparc64/dl.c | 46 +++++++++++++++++++++++-----------------------
kern/x86_64/dl.c | 6 +++---
5 files changed, 68 insertions(+), 64 deletions(-)
diff --git a/include/grub/elf.h b/include/grub/elf.h
index 49570a6..1a1ec13 100644
--- a/include/grub/elf.h
+++ b/include/grub/elf.h
@@ -2340,8 +2340,10 @@ typedef Elf32_Rel Elf_Rel;
typedef Elf32_Rela Elf_Rela;
typedef Elf32_Section Elf_Section;
typedef Elf32_Shdr Elf_Shdr;
+typedef Elf32_Sword Elf_Sword;
typedef Elf32_Sym Elf_Sym;
typedef Elf32_Word Elf_Word;
+typedef Elf32_Xword Elf_Xword;
#define ELF_ST_BIND(val) ELF32_ST_BIND(val)
#define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
@@ -2359,8 +2361,10 @@ typedef Elf64_Rel Elf_Rel;
typedef Elf64_Rela Elf_Rela;
typedef Elf64_Section Elf_Section;
typedef Elf64_Shdr Elf_Shdr;
+typedef Elf64_Sword Elf_Sword;
typedef Elf64_Sym Elf_Sym;
typedef Elf64_Word Elf_Word;
+typedef Elf64_Xword Elf_Xword;
#define ELF_ST_BIND(val) ELF64_ST_BIND (val)
#define ELF_ST_TYPE(val) ELF64_ST_TYPE (val)
diff --git a/kern/i386/dl.c b/kern/i386/dl.c
index a17f175..91121f6 100644
--- a/kern/i386/dl.c
+++ b/kern/i386/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS32
@@ -41,15 +41,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
- Elf32_Shdr *s;
- Elf32_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -58,9 +58,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_REL)
{
grub_dl_segment_t seg;
@@ -72,32 +72,32 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf32_Rel *rel, *max;
+ Elf_Rel *rel, *max;
- for (rel = (Elf32_Rel *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rel *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf32_Word *addr;
- Elf32_Sym *sym;
+ Elf_Word *addr;
+ Elf_Sym *sym;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf32_Sym *) ((char *) mod->symtab
- + entsize * ELF32_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_386_32:
*addr += sym->st_value;
break;
case R_386_PC32:
- *addr += (sym->st_value - (Elf32_Word) seg->addr
+ *addr += (sym->st_value - (Elf_Word) seg->addr
- rel->r_offset);
break;
}
diff --git a/kern/powerpc/dl.c b/kern/powerpc/dl.c
index 9b1cb14..2891b0d 100644
--- a/kern/powerpc/dl.c
+++ b/kern/powerpc/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS32
@@ -42,15 +42,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf32_Ehdr *e = ehdr;
- Elf32_Shdr *s;
- Elf32_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -59,9 +59,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
grub_dl_segment_t seg;
@@ -73,37 +73,37 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf32_Rela *rel, *max;
+ Elf_Rela *rel, *max;
- for (rel = (Elf32_Rela *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf32_Word *addr;
- Elf32_Sym *sym;
+ Elf_Word *addr;
+ Elf_Sym *sym;
grub_uint32_t value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf32_Sym *) ((char *) mod->symtab
- + entsize * ELF32_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
/* On the PPC the value does not have an explicit
addend, add it. */
value = sym->st_value + rel->r_addend;
- switch (ELF32_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_PPC_ADDR16_LO:
- *(Elf32_Half *) addr = value;
+ *(Elf_Half *) addr = value;
break;
case R_PPC_REL24:
{
- Elf32_Sword delta = value - (Elf32_Word) addr;
+ Elf_Sword delta = value - (Elf_Word) addr;
if (delta << 6 >> 6 != delta)
return grub_error (GRUB_ERR_BAD_MODULE, "Relocation overflow");
@@ -112,7 +112,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
}
case R_PPC_ADDR16_HA:
- *(Elf32_Half *) addr = (value + 0x8000) >> 16;
+ *(Elf_Half *) addr = (value + 0x8000) >> 16;
break;
case R_PPC_ADDR32:
@@ -120,13 +120,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
break;
case R_PPC_REL32:
- *addr = value - (Elf32_Word) addr;
+ *addr = value - (Elf_Word) addr;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"This relocation (%d) is not implemented yet",
- ELF32_R_TYPE (rel->r_info));
+ ELF_R_TYPE (rel->r_info));
}
}
}
diff --git a/kern/sparc64/dl.c b/kern/sparc64/dl.c
index 5334896..a4d99ff 100644
--- a/kern/sparc64/dl.c
+++ b/kern/sparc64/dl.c
@@ -26,7 +26,7 @@
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
- Elf64_Ehdr *e = ehdr;
+ Elf_Ehdr *e = ehdr;
/* Check the magic numbers. */
if (e->e_ident[EI_CLASS] != ELFCLASS64
@@ -42,15 +42,15 @@ grub_arch_dl_check_header (void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
- Elf64_Ehdr *e = ehdr;
- Elf64_Shdr *s;
- Elf64_Word entsize;
+ Elf_Ehdr *e = ehdr;
+ Elf_Shdr *s;
+ Elf_Word entsize;
unsigned i;
/* Find a symbol table. */
- for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf64_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
@@ -59,9 +59,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
entsize = s->sh_entsize;
- for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
+ for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum;
- i++, s = (Elf64_Shdr *) ((char *) s + e->e_shentsize))
+ i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
grub_dl_segment_t seg;
@@ -73,27 +73,27 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
if (seg)
{
- Elf64_Rela *rel, *max;
+ Elf_Rela *rel, *max;
- for (rel = (Elf64_Rela *) ((char *) e + s->sh_offset),
+ for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
{
- Elf64_Word *addr;
- Elf64_Sym *sym;
- Elf64_Addr value;
+ Elf_Word *addr;
+ Elf_Sym *sym;
+ Elf_Addr value;
if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment");
- addr = (Elf64_Word *) ((char *) seg->addr + rel->r_offset);
- sym = (Elf64_Sym *) ((char *) mod->symtab
- + entsize * ELF64_R_SYM (rel->r_info));
+ addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset);
+ sym = (Elf_Sym *) ((char *) mod->symtab
+ + entsize * ELF_R_SYM (rel->r_info));
value = sym->st_value + rel->r_addend;
- switch (ELF64_R_TYPE (rel->r_info) & 0xff)
+ switch (ELF_R_TYPE (rel->r_info) & 0xff)
{
case R_SPARC_32: /* 3 V-word32 */
if (value & 0xFFFFFFFF00000000)
@@ -102,13 +102,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
*addr = value;
break;
case R_SPARC_WDISP30: /* 7 V-disp30 */
- if (((value - (Elf64_Addr) addr) & 0xFFFFFFFF00000000) &&
- (((value - (Elf64_Addr) addr) & 0xFFFFFFFF00000000)
+ if (((value - (Elf_Addr) addr) & 0xFFFFFFFF00000000) &&
+ (((value - (Elf_Addr) addr) & 0xFFFFFFFF00000000)
!= 0xFFFFFFFF00000000))
return grub_error (GRUB_ERR_BAD_MODULE,
"Displacement out of 30 bits range");
*addr = (*addr & 0xC0000000) |
- (((grub_int32_t) ((value - (Elf64_Addr) addr) >> 2)) &
+ (((grub_int32_t) ((value - (Elf_Addr) addr) >> 2)) &
0x3FFFFFFF);
break;
case R_SPARC_HI22: /* 9 V-imm22 */
@@ -121,18 +121,18 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
*addr = (*addr & 0xFFFFFC00) | (value & 0x3FF);
break;
case R_SPARC_64: /* 32 V-xwords64 */
- *(Elf64_Xword *) addr = value;
+ *(Elf_Xword *) addr = value;
break;
case R_SPARC_OLO10:
*addr = (*addr & ~0x1fff)
| (((value & 0x3ff) +
- (ELF64_R_TYPE (rel->r_info) >> 8))
+ (ELF_R_TYPE (rel->r_info) >> 8))
& 0x1fff);
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"This relocation (%d) is not implemented yet",
- ELF64_R_TYPE (rel->r_info));
+ ELF_R_TYPE (rel->r_info));
}
}
}
diff --git a/kern/x86_64/dl.c b/kern/x86_64/dl.c
index 9e5de6e..73a7337 100644
--- a/kern/x86_64/dl.c
+++ b/kern/x86_64/dl.c
@@ -90,9 +90,9 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
addr32 = (Elf64_Word *) ((char *) seg->addr + rel->r_offset);
addr64 = (Elf64_Xword *) addr32;
sym = (Elf64_Sym *) ((char *) mod->symtab
- + entsize * ELF64_R_SYM (rel->r_info));
+ + entsize * ELF_R_SYM (rel->r_info));
- switch (ELF64_R_TYPE (rel->r_info))
+ switch (ELF_R_TYPE (rel->r_info))
{
case R_X86_64_64:
*addr64 += rel->r_addend + sym->st_value;
@@ -109,7 +109,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
break;
default:
- grub_fatal ("Unrecognized relocation: %d\n", ELF64_R_TYPE (rel->r_info));
+ grub_fatal ("Unrecognized relocation: %d\n", ELF_R_TYPE (rel->r_info));
}
}
}
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] Improve genmoddep.awk
2009-07-01 0:35 [PATCH 1/3] Improve genmoddep.awk Pavel Roskin
2009-07-01 0:35 ` [PATCH 2/3] Don't put modules without dependencies into moddep.lst Pavel Roskin
2009-07-01 0:35 ` [PATCH 3/3] Use ELF symbols without "32" or "64" Pavel Roskin
@ 2009-07-01 3:44 ` Bean
2009-07-01 4:51 ` Pavel Roskin
2 siblings, 1 reply; 11+ messages in thread
From: Bean @ 2009-07-01 3:44 UTC (permalink / raw)
To: The development of GRUB 2
Hi,
Perhaps you could also take a look at my previous patch
[PATCH] Use symbol database to maintain module dependence
It add a program grub-symdb to maintain symbol database and therefore
eliminate def- and unf- files, it also allows incremental build.
On Wed, Jul 1, 2009 at 8:35 AM, Pavel Roskin<proski@gnu.org> wrote:
> Avoid pipeline in its invocation. It's hard to get the result of a
> pipeline reliably. Eliminate the need in "und-*" files by caching and
> postprocessing undefined symbols.
>
> ChangeLog:
>
> * Makefile.in: Invoke genmoddep.awk without any pipelines.
> Eliminate UNDSYMFILES.
> * genmk.rb: Write undefined symbols to the same files as defined
> symbols.
> * genmoddep.awk: Process only files from the command line,
> recognize defined symbols by the number of records. Save
> undefined symbols in a table, process them later. Output to the
> file specified by the MODDEP environment variable. Report all
> undefined symbols.
> ---
>
> Makefile.in | 6 ++----
> genmk.rb | 17 ++++++-----------
> genmoddep.awk | 39 ++++++++++++++++++++++++---------------
> 3 files changed, 32 insertions(+), 30 deletions(-)
>
> diff --git a/Makefile.in b/Makefile.in
> index f82566a..e6be9c4 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -148,10 +148,8 @@ include $(srcdir)/conf/$(target_cpu)-$(platform).mk
>
> CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA)
> pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst
> -moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk
> - cat $(DEFSYMFILES) /dev/null \
> - | $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \
> - || (rm -f $@; exit 1)
> +moddep.lst: $(DEFSYMFILES) genmoddep.awk
> + MODDEP=$@ $(AWK) -f $(srcdir)/genmoddep.awk $(DEFSYMFILES)
>
> command.lst: $(COMMANDFILES)
> cat $^ /dev/null | sort > $@
> diff --git a/genmk.rb b/genmk.rb
> index e3866c1..2883362 100644
> --- a/genmk.rb
> +++ b/genmk.rb
> @@ -110,17 +110,15 @@ class PModule
> mod_src = 'mod-' + @name.suffix('c')
> mod_obj = mod_src.suffix('o')
> defsym = 'def-' + @name.suffix('lst')
> - undsym = 'und-' + @name.suffix('lst')
> mod_name = File.basename(@name, '.mod')
> symbolic_name = mod_name.sub(/\.[^\.]*$/, '')
>
> - "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym}
> + "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str}
> ifneq ($(#{prefix}_EXPORTS),no)
> CLEANFILES += #{defsym}
> DEFSYMFILES += #{defsym}
> endif
> MOSTLYCLEANFILES += #{deps_str}
> -UNDSYMFILES += #{undsym}
>
> ifneq ($(TARGET_APPLE_CC),1)
> #{@name}: #{pre_obj} #{mod_obj} $(TARGET_OBJ2ELF)
> @@ -148,19 +146,16 @@ endif
> sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
>
> ifneq ($(#{prefix}_EXPORTS),no)
> -ifneq ($(TARGET_APPLE_CC),1)
> #{defsym}: #{pre_obj}
> - $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
> + echo '#{mod_name}' > $@
> + $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
> +ifneq ($(TARGET_APPLE_CC),1)
> + $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' >> $@
> else
> -#{defsym}: #{pre_obj}
> - $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
> + $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' >> $@
> endif
> endif
>
> -#{undsym}: #{pre_obj}
> - echo '#{mod_name}' > $@
> - $(NM) -u -P -p $< | cut -f1 -d' ' >> $@
> -
> " + objs.collect_with_index do |obj, i|
> src = sources[i]
> fake_obj = File.basename(src).suffix('o')
> diff --git a/genmoddep.awk b/genmoddep.awk
> index f7f085e..db8e07e 100644
> --- a/genmoddep.awk
> +++ b/genmoddep.awk
> @@ -11,11 +11,14 @@
> # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
> # PARTICULAR PURPOSE.
>
> -# Read defined symbols from stdin.
> -BEGIN {
> - while (getline <"/dev/stdin") {
> - symtab[$1] = $2
> - }
> +# This program processes lists of defined and undefined symbols given on
> +# the command line. The output filename is determined by the MODDEP
> +# environment variable.
> +
> +# Each defined symbol is followed by the module name.
> +NF == 2 {
> + symtab[$1] = $2
> + next
> }
>
> # The first line contains a module name.
> @@ -25,19 +28,25 @@ FNR == 1 {
> };
>
> # The rest is undefined symbols.
> -{
> - if ($1 in symtab) {
> - modtab[module] = modtab[module] " " symtab[$1];
> - }
> - else {
> - printf "%s in %s is not defined\n", $1, module >"/dev/stderr";
> - error++;
> - exit;
> - }
> +NF == 1 {
> + undtab[$1] = undtab[$1] " " module
> }
>
> # Output the result.
> END {
> + for (sym in undtab) {
> + if (sym in symtab) {
> + split(undtab[sym], mods, " ");
> + for (i in mods) {
> + modtab[mods[i]] = modtab[mods[i]] " " symtab[sym];
> + }
> + }
> + else {
> + printf "Symbol \"%s\" is not defined in modules:%s\n", sym, undtab[sym] >"/dev/stderr";
> + error = 1;
> + }
> + }
> +
> if (error == 1)
> exit 1;
>
> @@ -57,6 +66,6 @@ END {
> for (depmod in uniqmods) {
> modlist = modlist " " depmod;
> }
> - printf "%s:%s\n", mod, modlist;
> + printf "%s:%s\n", mod, modlist >ENVIRON["MODDEP"];
> }
> }
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Bean
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] Improve genmoddep.awk
2009-07-01 3:44 ` [PATCH 1/3] Improve genmoddep.awk Bean
@ 2009-07-01 4:51 ` Pavel Roskin
2009-07-01 5:22 ` Bean
0 siblings, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 4:51 UTC (permalink / raw)
To: grub-devel
Quoting Bean <bean123ch@gmail.com>:
> Perhaps you could also take a look at my previous patch
>
> [PATCH] Use symbol database to maintain module dependence
>
> It add a program grub-symdb to maintain symbol database and therefore
> eliminate def- and unf- files, it also allows incremental build.
grub-symdb would need to be compiled by a native C compiler.
Otherwise, it won't work when cross-compiling the utilities.
It's not that it's a big deal per se, but it is will add complexity if
we try to use autoconf to look for it.
Adding grub-symdb to bin_UTILITIES would result in it being installed
along with the utilities that are actually used after the build. I
think it's wrong. Temporary build tools don't belong there.
I think awk is a better choice than native C, as it's assumed to be
available on the build system. I could rewrite genmoddep.awk in shell
script, if we want to eliminate awk from the build. But I'm not sure
every shell would handle the needed amount of environment variables to
emulate arrays. And it would be almost certainly slower.
The awk script could be changed to run nm and to parse output of
different kinds on nm. We could probably remove another Apple hack
from the makefiles by having awk do the parsing.
I think we could specify the dependencies manually and have the script
check them rather than generate them. That would mean that no
dependencies will be created unknowingly. Chances are it will allow
more incremental builds.
Going offtopic, another approach to avoid massive rebuilds for minor
changes would be to ban most typedefs, so that we can use forward
declarations for structures instead of including files that are
otherwise unneeded (fresh example: dl.h including elf.h just to use a
pointer to the structure).
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] Improve genmoddep.awk
2009-07-01 4:51 ` Pavel Roskin
@ 2009-07-01 5:22 ` Bean
2009-07-01 12:35 ` Pavel Roskin
2009-07-01 13:13 ` Robert Millan
0 siblings, 2 replies; 11+ messages in thread
From: Bean @ 2009-07-01 5:22 UTC (permalink / raw)
To: The development of GRUB 2
On Wed, Jul 1, 2009 at 12:51 PM, Pavel Roskin<proski@gnu.org> wrote:
> Quoting Bean <bean123ch@gmail.com>:
>
>> Perhaps you could also take a look at my previous patch
>>
>> [PATCH] Use symbol database to maintain module dependence
>>
>> It add a program grub-symdb to maintain symbol database and therefore
>> eliminate def- and unf- files, it also allows incremental build.
>
> grub-symdb would need to be compiled by a native C compiler. Otherwise, it
> won't work when cross-compiling the utilities.
>
> It's not that it's a big deal per se, but it is will add complexity if we
> try to use autoconf to look for it.
>
> Adding grub-symdb to bin_UTILITIES would result in it being installed along
> with the utilities that are actually used after the build. I think it's
> wrong. Temporary build tools don't belong there.
Hi,
Actually, that's the intention. grub-symdb and the symbol database is
supposed to be installed in the target system. They can be used to
support external grub modules. To install new package, we can just
copy the modules files and use rerun grub-symdb to update the
database.
>
> I think awk is a better choice than native C, as it's assumed to be
> available on the build system. I could rewrite genmoddep.awk in shell
> script, if we want to eliminate awk from the build. But I'm not sure every
> shell would handle the needed amount of environment variables to emulate
> arrays. And it would be almost certainly slower.
>
> The awk script could be changed to run nm and to parse output of different
> kinds on nm. We could probably remove another Apple hack from the makefiles
> by having awk do the parsing.
With grub-symdb, there is no need to relied on nm, I think this would
make it more portable.
>
> I think we could specify the dependencies manually and have the script check
> them rather than generate them. That would mean that no dependencies will
> be created unknowingly. Chances are it will allow more incremental builds.
With the build system, there is a lot of unnecessary rebuilds, as it
relies on a central moddep.lst:
pre-*.o => moddep.lst => mod-*.c => *.mod
As you can see, modification to any source file would cause all the
modules files to be rebuild. Although for most of them, it's only the
trunk, but there is still a lot of necessary work.
--
Bean
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] Improve genmoddep.awk
2009-07-01 5:22 ` Bean
@ 2009-07-01 12:35 ` Pavel Roskin
2009-07-01 13:13 ` Robert Millan
1 sibling, 0 replies; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 12:35 UTC (permalink / raw)
To: grub-devel
Quoting Bean <bean123ch@gmail.com>:
> On Wed, Jul 1, 2009 at 12:51 PM, Pavel Roskin<proski@gnu.org> wrote:
>> Quoting Bean <bean123ch@gmail.com>:
>>
>>> Perhaps you could also take a look at my previous patch
>>>
>>> [PATCH] Use symbol database to maintain module dependence
>>>
>>> It add a program grub-symdb to maintain symbol database and therefore
>>> eliminate def- and unf- files, it also allows incremental build.
>>
>> grub-symdb would need to be compiled by a native C compiler. Otherwise, it
>> won't work when cross-compiling the utilities.
>>
>> It's not that it's a big deal per se, but it is will add complexity if we
>> try to use autoconf to look for it.
>>
>> Adding grub-symdb to bin_UTILITIES would result in it being installed along
>> with the utilities that are actually used after the build. I think it's
>> wrong. Temporary build tools don't belong there.
>
> Hi,
>
> Actually, that's the intention. grub-symdb and the symbol database is
> supposed to be installed in the target system. They can be used to
> support external grub modules. To install new package, we can just
> copy the modules files and use rerun grub-symdb to update the
> database.
Oh, I see! I'll need to take a closer look.
> With the build system, there is a lot of unnecessary rebuilds, as it
> relies on a central moddep.lst:
>
> pre-*.o => moddep.lst => mod-*.c => *.mod
>
> As you can see, modification to any source file would cause all the
> modules files to be rebuild. Although for most of them, it's only the
> trunk, but there is still a lot of necessary work.
Then moddep.lst should not be touched if the result is the same. That
shouldn't be hard to do.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] Don't put modules without dependencies into moddep.lst
2009-07-01 0:35 ` [PATCH 2/3] Don't put modules without dependencies into moddep.lst Pavel Roskin
@ 2009-07-01 13:10 ` Robert Millan
2009-07-01 13:20 ` Pavel Roskin
0 siblings, 1 reply; 11+ messages in thread
From: Robert Millan @ 2009-07-01 13:10 UTC (permalink / raw)
To: The development of GRUB 2
On Tue, Jun 30, 2009 at 08:35:09PM -0400, Pavel Roskin wrote:
> + if (modlist != "") {
Are you sure this does what you expect? I read it as "compare this
char * with this const char *", which will always return false.
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] Improve genmoddep.awk
2009-07-01 5:22 ` Bean
2009-07-01 12:35 ` Pavel Roskin
@ 2009-07-01 13:13 ` Robert Millan
1 sibling, 0 replies; 11+ messages in thread
From: Robert Millan @ 2009-07-01 13:13 UTC (permalink / raw)
To: The development of GRUB 2
On Wed, Jul 01, 2009 at 01:22:29PM +0800, Bean wrote:
> On Wed, Jul 1, 2009 at 12:51 PM, Pavel Roskin<proski@gnu.org> wrote:
> > Quoting Bean <bean123ch@gmail.com>:
> >
> >> Perhaps you could also take a look at my previous patch
> >>
> >> [PATCH] Use symbol database to maintain module dependence
> >>
> >> It add a program grub-symdb to maintain symbol database and therefore
> >> eliminate def- and unf- files, it also allows incremental build.
> >
> > grub-symdb would need to be compiled by a native C compiler. Otherwise, it
> > won't work when cross-compiling the utilities.
> >
> > It's not that it's a big deal per se, but it is will add complexity if we
> > try to use autoconf to look for it.
> >
> > Adding grub-symdb to bin_UTILITIES would result in it being installed along
> > with the utilities that are actually used after the build. I think it's
> > wrong. Temporary build tools don't belong there.
>
> Hi,
>
> Actually, that's the intention. grub-symdb and the symbol database is
> supposed to be installed in the target system. They can be used to
> support external grub modules. To install new package, we can just
> copy the modules files and use rerun grub-symdb to update the
> database.
I tend to agree with Pavel. We should be careful about adding complexity,
and only do it when we're sure it's going to pay off.
(I'm not saying it doesn't pay off here, but this factor should always be
taken into account IMO)
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] Don't put modules without dependencies into moddep.lst
2009-07-01 13:10 ` Robert Millan
@ 2009-07-01 13:20 ` Pavel Roskin
2009-07-04 20:09 ` Robert Millan
0 siblings, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-01 13:20 UTC (permalink / raw)
To: grub-devel
Quoting Robert Millan <rmh@aybabtu.com>:
> On Tue, Jun 30, 2009 at 08:35:09PM -0400, Pavel Roskin wrote:
>> + if (modlist != "") {
>
> Are you sure this does what you expect? I read it as "compare this
> char * with this const char *", which will always return false.
Yes, this check does the right thing. And we do the same thing elsewhere:
if (depmod != "kernel" && depmod != mod)
Even the gawk info page has it:
if ($(NF+1) != "")
It works with POSIXLY_CORRECT too.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] Don't put modules without dependencies into moddep.lst
2009-07-01 13:20 ` Pavel Roskin
@ 2009-07-04 20:09 ` Robert Millan
0 siblings, 0 replies; 11+ messages in thread
From: Robert Millan @ 2009-07-04 20:09 UTC (permalink / raw)
To: The development of GRUB 2
On Wed, Jul 01, 2009 at 09:20:49AM -0400, Pavel Roskin wrote:
> Quoting Robert Millan <rmh@aybabtu.com>:
>
>> On Tue, Jun 30, 2009 at 08:35:09PM -0400, Pavel Roskin wrote:
>>> + if (modlist != "") {
>>
>> Are you sure this does what you expect? I read it as "compare this
>> char * with this const char *", which will always return false.
>
> Yes, this check does the right thing. And we do the same thing elsewhere:
>
> if (depmod != "kernel" && depmod != mod)
>
> Even the gawk info page has it:
Oh, I thought you were writing C.
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-07-04 20:10 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 0:35 [PATCH 1/3] Improve genmoddep.awk Pavel Roskin
2009-07-01 0:35 ` [PATCH 2/3] Don't put modules without dependencies into moddep.lst Pavel Roskin
2009-07-01 13:10 ` Robert Millan
2009-07-01 13:20 ` Pavel Roskin
2009-07-04 20:09 ` Robert Millan
2009-07-01 0:35 ` [PATCH 3/3] Use ELF symbols without "32" or "64" Pavel Roskin
2009-07-01 3:44 ` [PATCH 1/3] Improve genmoddep.awk Bean
2009-07-01 4:51 ` Pavel Roskin
2009-07-01 5:22 ` Bean
2009-07-01 12:35 ` Pavel Roskin
2009-07-01 13:13 ` Robert Millan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.