elf: Calculate symbol size if needed
PATCH 1/1 elf: Calculate symbol size if needed
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
Assume that the size of such symbols is the difference to the next symbol value.
--- hw/elf_ops.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
hw/elf_ops.h +5 -0
@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, syms =qemu_realloc (syms, nsyms *sizeof (*syms));qsort (syms, nsyms,sizeof (*syms),glue (symcmp,SZ )); +for (i =0 ; i < nsyms -1 ; i++) { +if (syms[i].st_size ==0 ) { + syms[i].st_size = syms[i +1 ].st_value - syms[i].st_value; + } + } }else {qemu_free (syms); syms =NULL ;
Signature · 1 line
1.7.1
Quoted 6 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 13 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil <[email protected]>---
hw/elf_ops.h | 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0
hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, · line 160
Quoted 8 lines
hw/elf_ops.h +5
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, syms = qemu_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); + for (i = 0; i < nsyms - 1; i++) { + if (syms[i].st_size == 0) { + syms[i].st_size = syms[i + 1].st_value - syms[i].st_value; + } + }
The size of the last symbol is not guesstimated, it could be assumed to be _etext - syms[nsyms].st_value.
Quoted 8 lines
hw/elf_ops.h +0
-1} else { qemu_free(syms); syms = NULL; --1.7.1
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 12 lines · Stefan Weil
Quoted 8 lines
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
It's not just ARM. ARM is just an example.
But I stumbled upon this problem when running the linux start code from arch/arm/kernel/head.S.
Quoted 15 lines
Quoted 15 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>--- hw/elf_ops.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, syms =qemu_realloc (syms, nsyms *sizeof (*syms));
Quoted 10 lines
hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
Quoted 7 lines
hw/elf_ops.h +5
-0qsort (syms, nsyms,sizeof (*syms),glue (symcmp,SZ )); +for (i =0 ; i< nsyms -1 ; i++) { +if (syms[i].st_size ==0 ) { + syms[i].st_size = syms[i +1 ].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.
Or better
syms[nsyms - 1].st_size = _etext - syms[nsyms - 1].st_value
Even that would be wrong if the last symbol is not in the text segment but data.
Programming that special case just to get perhaps one last symbol size seems too much perfectionism.
Most symbols have a size != 0, so let's hope the last symbol has one, too :-)
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 28 lines · Stefan Weil
Quoted 8 lines
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 15 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>--- hw/elf_ops.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, syms =qemu_realloc (syms, nsyms *sizeof (*syms));
Quoted 17 lines
hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
Quoted 7 lines
hw/elf_ops.h +5
-0qsort (syms, nsyms,sizeof (*syms),glue (symcmp,SZ )); +for (i =0 ; i< nsyms -1 ; i++) { +if (syms[i].st_size ==0 ) { + syms[i].st_size = syms[i +1 ].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 5 lines
hw/elf_ops.h +0
-0}else {qemu_free (syms);syms = NULL;--
1.7.1
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed. Was I wrong, or can it be applied?
Quoted 56 lines · Stefan Weil
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 33 lines · Stefan Weil
Quoted 9 lines
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 17 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>---
hw/elf_ops.h | 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, syms = qemu_realloc(syms, nsyms * sizeof(*syms));Quoted 20 lines
hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
Quoted 8 lines
hw/elf_ops.h +5
-0qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); + for (i = 0; i< nsyms - 1; i++) { + if (syms[i].st_size == 0) { + syms[i].st_size = syms[i + 1].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 6 lines
} else {
qemu_free(syms);
syms = NULL;
--
1.7.1
Quoted 3 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed. Was I wrong, or can it be applied?
Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
Am 09.09.2010 20:44, schrieb Blue Swirl:
Quoted 58 lines · Stefan Weil
Quoted 57 lines
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 54 lines
Quoted 8 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 15 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>--- hw/elf_ops.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr · line 163
Quoted 10 lines
hw/elf_ops.h +5
-0syms =qemu_realloc (syms, nsyms *sizeof (*syms));qsort (syms, nsyms,sizeof (*syms),glue (symcmp,SZ )); +for (i =0 ; i< nsyms -1 ; i++) { +if (syms[i].st_size ==0 ) { + syms[i].st_size = syms[i +1 ].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 6 lines
} else { qemu_free(syms); syms = NULL;--
1.7.1
Quoted 6 lines
Quoted 3 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed. Was I wrong, or can it be applied?Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
The last symbol is one of several thousands, and most symbols don't need a fix, so with my fix more than 99.9 or even 99.99 percent of all symbols are ok :-) If the last symbol happens to be wrong, there is still a high probability that nobody will notice this because it is unused by QEMU. The problem I faced with QEMU's disassembly came from symbols with an address followed by code. Is there any code after the last symbol? I don't expect that. In a sorted list of symbols from the text segment, _etext should be the last symbols!
I think that the small chance of a missing fix for the last symbol is in no relation to the code needed.
Even worse, I have no simple formula to guess a valid value for the last symbol. The formula you suggested (with the corrections I wrote in my reply) is only ok if the last symbol is in the text segment. Usually there are also symbols for data in other segments, and in many cases these segments are located after the text segment. In these cases the last symbol is not located in the text segment which makes guesses of its size much more complicated.
To make it short: I don't know how to fix the last symbol in a reasonable way.
Sorry,
Stefan
Quoted 86 lines · Stefan Weil
Am 09.09.2010 20:44, schrieb Blue Swirl:
Quoted 60 lines · Stefan Weil
Quoted 58 lines
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 54 lines
Quoted 8 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 15 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>---
hw/elf_ops.h | 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr · line 163
Quoted 10 lines
hw/elf_ops.h +5
-0syms = qemu_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); + for (i = 0; i< nsyms - 1; i++) { + if (syms[i].st_size == 0) { + syms[i].st_size = syms[i + 1].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 6 lines
} else {
qemu_free(syms);
syms = NULL;
--
1.7.1Quoted 6 lines
Quoted 3 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed. Was I wrong, or can it be applied?Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
The last symbol is one of several thousands, and most symbols don't need a fix,
so with my fix more than 99.9 or even 99.99 percent of all symbols are ok :-)
If the last symbol happens to be wrong, there is still a high probability that
nobody will notice this because it is unused by QEMU. The problem I faced with
QEMU's disassembly came from symbols with an address followed by code. Is there any code after the last symbol? I don't expect that. In a sorted list
of symbols from the text segment,_etextshould be the last symbols!I think that the small chance of a missing fix for the last symbol is in no relation
to the code needed.
Quoted 10 lines
Even worse, I have no simple formula to guess a valid value for the last symbol.
The formula you suggested (with the corrections I wrote in my reply) is only ok
if the last symbol is in the text segment. Usually there are also symbols for data
in other segments, and in many cases these segments are located after the text segment. In these cases the last symbol is not located in the text segment
which makes guesses of its size much more complicated.
How about using _end then?
Am 09.09.2010 21:29, schrieb Blue Swirl:
Quoted 99 lines · Stefan Weil
Quoted 87 lines
Am 09.09.2010 20:44, schrieb Blue Swirl:
Quoted 59 lines · Stefan Weil
Quoted 58 lines
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 54 lines
Quoted 8 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 15 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>--- hw/elf_ops.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr · line 163
Quoted 10 lines
hw/elf_ops.h +5
-0syms =qemu_realloc (syms, nsyms *sizeof (*syms));qsort (syms, nsyms,sizeof (*syms),glue (symcmp,SZ )); +for (i =0 ; i< nsyms -1 ; i++) { +if (syms[i].st_size ==0 ) { + syms[i].st_size = syms[i +1 ].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 6 lines
} else { qemu_free(syms); syms = NULL;--
1.7.1Quoted 7 lines
Quoted 4 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed.
Was I wrong, or can it be applied?Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
The last symbol is one of several thousands, and most symbols don't need a fix,
so with my fix more than 99.9 or even 99.99 percent of all symbols are ok :-)
If the last symbol happens to be wrong, there is still a high probability that
nobody will notice this because it is unused by QEMU. The problem I faced with
QEMU's disassembly came from symbols with an address followed by code. Is there any code after the last symbol? I don't expect that. In a sorted list
of symbols from the text segment,_etextshould be the last symbols!I think that the small chance of a missing fix for the last symbol is in no relation
to the code needed.Quoted 11 lines
Even worse, I have no simple formula to guess a valid value for the last symbol.
The formula you suggested (with the corrections I wrote in my reply) is only ok
if the last symbol is in the text segment. Usually there are also symbols for data
in other segments, and in many cases these segments are located after the text segment. In these cases the last symbol is not located in the text segment
which makes guesses of its size much more complicated.
Quoted 3 lines
How about using
_endthen?
Wouldn't _end be the last symbol then?
Quoted 118 lines · Stefan Weil
Am 09.09.2010 21:29, schrieb Blue Swirl:
Quoted 117 lines · Stefan Weil
Quoted 114 lines
Am 09.09.2010 20:44, schrieb Blue Swirl:
Quoted 69 lines
Quoted 65 lines · Stefan Weil
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 61 lines
Quoted 9 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 16 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>---
hw/elf_ops.h | 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr · line 163
Quoted 10 lines
hw/elf_ops.h +5
-0syms = qemu_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); + for (i = 0; i< nsyms - 1; i++) { + if (syms[i].st_size == 0) { + syms[i].st_size = syms[i + 1].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 7 lines
} else {
qemu_free(syms);
syms = NULL;
--
1.7.1Quoted 9 lines
Quoted 5 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed.
Was I wrong, or can it be applied?Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
The last symbol is one of several thousands, and most symbols don't need a
fix,
so with my fix more than 99.9 or even 99.99 percent of all symbols are ok :-)
If the last symbol happens to be wrong, there is still a high probability that
nobody will notice this because it is unused by QEMU. The problem I faced with
QEMU's disassembly came from symbols with an address followed by code. Is there any code after the last symbol? I don't expect that. In a sorted list
of symbols from the text segment,_etextshould be the last symbols!I think that the small chance of a missing fix for the last symbol is in no
relation
to the code needed.Even worse, I have no simple formula to guess a valid value for the last symbol.
The formula you suggested (with the corrections I wrote in my reply) is only
ok
if the last symbol is in the text segment. Usually there are also symbols for data
in other segments, and in many cases these segments are located after the text segment. In these cases the last symbol is not located in the text segment
which makes guesses of its size much more complicated.
Quoted 5 lines
Quoted 3 lines
How about using
_endthen?Wouldn't
_endbe the last symbol then?
Right, _end should be the last one in any case. I'll apply the patch.
Quoted 119 lines · Blue Swirl
Quoted 118 lines · Stefan Weil
Am 09.09.2010 21:29, schrieb Blue Swirl:
Quoted 117 lines · Stefan Weil
Quoted 114 lines
Am 09.09.2010 20:44, schrieb Blue Swirl:
Quoted 69 lines
Quoted 65 lines · Stefan Weil
Am 11.08.2010 18:21, schrieb Blue Swirl:
Quoted 61 lines
Quoted 9 lines · Stefan Weil
Symbols with a size of 0 are unusable for the disassembler.
Example:
While running an arm linux kernel, no symbolic names are used in qemu.log when the cpu is executing an assembler function.
That is a problem of the assembler function, it should use '.size' directive like what happens when C code is compiled. And why just ARM?
Quoted 16 lines
Assume that the size of such symbols is the difference to the next symbol value.
Signed-off-by Stefan Weil<[email protected]>---
hw/elf_ops.h | 5 +++++1 files changed, 5 insertions(+), 0 deletions(-)hw/elf_ops.h +0
-0@@ -153,6 +153,11 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,hw/elf_ops.h static int glue(load_symbols, SZ)(struct elfhdr · line 163
Quoted 10 lines
hw/elf_ops.h +5
-0syms = qemu_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); + for (i = 0; i< nsyms - 1; i++) { + if (syms[i].st_size == 0) { + syms[i].st_size = syms[i + 1].st_value - syms[i].st_value; + } + }The size of the last symbol is not guesstimated, it could be assumed to be
_etext- syms[nsyms].st_value.Quoted 7 lines
} else {
qemu_free(syms);
syms = NULL;
--
1.7.1Quoted 9 lines
Quoted 5 lines
The patch is still missing in qemu master.
From the two feedbacks I did not read that anything needs to be changed.
Was I wrong, or can it be applied?Please fix the last symbol. Either we should fix all symbols or none, half fixed (OK, practically all) is not so great.
The last symbol is one of several thousands, and most symbols don't need a
fix,
so with my fix more than 99.9 or even 99.99 percent of all symbols are ok :-)
If the last symbol happens to be wrong, there is still a high probability that
nobody will notice this because it is unused by QEMU. The problem I faced with
QEMU's disassembly came from symbols with an address followed by code. Is there any code after the last symbol? I don't expect that. In a sorted list
of symbols from the text segment,_etextshould be the last symbols!I think that the small chance of a missing fix for the last symbol is in no
relation
to the code needed.Even worse, I have no simple formula to guess a valid value for the last symbol.
The formula you suggested (with the corrections I wrote in my reply) is only
ok
if the last symbol is in the text segment. Usually there are also symbols for data
in other segments, and in many cases these segments are located after the text segment. In these cases the last symbol is not located in the text segment
which makes guesses of its size much more complicated.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
How about using
_endthen?Wouldn't
_endbe the last symbol then?Right,
_endshould be the last one in any case. I'll apply the patch.
I'm not so sure that is the case. The load_symbols call throws away symbols that are not typed as functions. The filtering is done prior to the suggested size fixups so my guess is that _end is typically gone when the suggested size fixup is done.
I'm not opposed to the patch though...
Cheers