Skip to contentSkip to conversation

fix perf Annotation of Thumb code

PATCH In review Dr. David Alan Gilbert 3 participants 6 messages Jan 21, 2011 – Jan 22, 2011 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix perf Annotation of Thumb code

Hi,
In ARM's Thumb mode the bottom bit of the symbol address is set to mark
the function as Thumb; the instructions are in reality 2 or 4 byte on 2 byte alignments, and when the +1 address is used in annotate it causes objdump to disassemble invalid instructions.

The patch removes that bottom bit during symbol loading.
This patch is against current linus's git, (2b1caf.....).
Many thinks to Dave Martin for comments on an initial version of the patch.

Dave

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

---

tools/perf/util/symbol.c +7 -0
index 15ccfba..36e76c1 100644
@@ -1161,6 +1161,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 
 		section_name = elf_sec__name(&shdr, secstrs);
 
+		/* On ARM, symbols for thumb functions have 1 added to
+		 * the symbol address as a flag - remove it */
+		if ((ehdr.e_machine == EM_ARM) &&
+			(map->type == MAP__FUNCTION) &&
+			(sym.st_value & 1))
+			sym.st_value-=1;
+
 		if (self->kernel != DSO_TYPE_USER || kmodule) {
 			char dso_name[PATH_MAX];
 
#1 lore raw

Em Fri, Jan 21, 2011 at 04:40:19PM +0000, Dr. David Alan Gilbert escreveu:

Quoted 9 lines

Hi,
In ARM's Thumb mode the bottom bit of the symbol address is set to mark
the function as Thumb; the instructions are in reality 2 or 4 byte on 2 byte alignments, and when the +1 address is used in annotate it causes objdump to disassemble invalid instructions.

The patch removes that bottom bit during symbol loading.
This patch is against current linus's git, (2b1caf.....).
Many thinks to Dave Martin for comments on an initial version of the patch.

Thanks, adding it to perf/urgent.

- Arnaldo

Quoted 27 lines

Dave

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

---

tools/perf/util/symbol.c +7 -0
index 15ccfba..36e76c1 100644
@@ -1161,6 +1161,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 
 		section_name = elf_sec__name(&shdr, secstrs);
 
+		/* On ARM, symbols for thumb functions have 1 added to
+		 * the symbol address as a flag - remove it */
+		if ((ehdr.e_machine == EM_ARM) &&
+			(map->type == MAP__FUNCTION) &&
+			(sym.st_value & 1))
+			sym.st_value-=1;
+
 		if (self->kernel != DSO_TYPE_USER || kmodule) {
 			char dso_name[PATH_MAX];
 
#2 lore raw
In reply to Dr. David Alan Gilbert

Hello.

Quoted 10 lines · Dr. David Alan Gilbert

In ARM's Thumb mode the bottom bit of the symbol address is set to mark
the function as Thumb; the instructions are in reality 2 or 4 byte on 2 byte alignments, and when the +1 address is used in annotate it causes objdump to disassemble invalid instructions.

The patch removes that bottom bit during symbol loading.
This patch is against current linus's git, (2b1caf.....).
Many thinks to Dave Martin for comments on an initial version of the patch.

Quoted 6 lines

Dave

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

Hm, I think there should be no spaces/tabs before signoff...

Quoted 7 lines

---

tools/perf/util/symbol.c +0 -0
index 15ccfba..36e76c1 100644

tools/perf/util/symbol.c static int dso__load_sym(struct dso *self, struct map *map, const char *name, · line 1169

Quoted 9 lines
tools/perf/util/symbol.c +6 -0
@@ -1161,6 +1161,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 
 		section_name = elf_sec__name(&shdr, secstrs);
 
+		/* On ARM, symbols for thumb functions have 1 added to
+		 * the symbol address as a flag - remove it */
+		if ((ehdr.e_machine == EM_ARM) &&
+			(map->type == MAP__FUNCTION) &&
+			(sym.st_value & 1))
+			sym.st_value-=1;

The coding style used suggests spaces around -=.

WBR, Sergei

#3 lore raw

Em Fri, Jan 21, 2011 at 08:17:18PM +0300, Sergei Shtylyov escreveu:

Quoted 5 lines
Quoted 4 lines

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

Quoted 7 lines

Hm, I think there should be no spaces/tabs before signoff...

tools/perf/util/symbol.c static int dso__load_sym(struct dso *self, struct map *map, const char *name, · line 1169

Quoted 1 line
tools/perf/util/symbol.c +1 -0
+			sym.st_value-=1;

The coding style used suggests spaces around -=.

WBR, Sergei

I noticed both issues and will fix them up when applying the patch.

Thanks

- Arnaldo

#4 lore raw
Quoted 8 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 21, 2011 at 08:17:18PM +0300, Sergei Shtylyov escreveu:

Quoted 7 lines
Quoted 4 lines

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

? ? ? ?Signed-off-by: Dr. David Alan Gilbert <[email protected]>

? ?Hm, I think there should be no spaces/tabs before signoff...

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

+ ? ? ? ? ? ? ? ? ? ?sym.st_value-=1;

? The coding style used suggests spaces around -=.

WBR, Sergei

I noticed both issues and will fix them up when applying the patch.

Oops, sorry about those. Thanks Sergei, Arnaldo.

Dave

#5 lore raw

[tip:perf/urgent] perf symbols: Fix annotation of thumb code

In reply to Dr. David Alan Gilbert
Commit-ID:  b2f8fb237e9cc407a02aca401369c15babae35dd
Gitweb:     http://git.kernel.org/tip/b2f8fb237e9cc407a02aca401369c15babae35dd
Author:     Dr. David Alan Gilbert <[email protected]>
AuthorDate: Fri, 21 Jan 2011 16:40:19 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 21 Jan 2011 16:32:18 -0200

perf symbols: Fix annotation of thumb code

In ARM's Thumb mode the bottom bit of the symbol address is set to mark the function as Thumb; the instructions are in reality 2 or 4 byte on 2 byte alignments, and when the +1 address is used in annotate it causes objdump to disassemble invalid instructions.

The patch removes that bottom bit during symbol loading.

Many thinks to Dave Martin for comments on an initial version of the patch.

(For reference this corresponds to this bug
https://bugs.launchpad.net/linux-linaro/+bug/677547 )

Cc: Ingo Molnar <[email protected]>
Cc: Dave Martin <[email protected]>
LKML-Reference: <20110121163922.GA31398@davesworkthinkpad>

---
 tools/perf/util/symbol.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
tools/perf/util/symbol.c +7 -0
index 15ccfba..e32478e 100644
@@ -1161,6 +1161,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 
 		section_name = elf_sec__name(&shdr, secstrs);
 
+		/* On ARM, symbols for thumb functions have 1 added to
+		 * the symbol address as a flag - remove it */
+		if ((ehdr.e_machine == EM_ARM) &&
+		    (map->type == MAP__FUNCTION) &&
+		    (sym.st_value & 1))
+			--sym.st_value;
+
 		if (self->kernel != DSO_TYPE_USER || kmodule) {
 			char dso_name[PATH_MAX];