linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] objtool: support symtab_shndx during dump
@ 2020-08-12 17:57 Kristen Carlson Accardi
  2020-09-03 11:43 ` Miroslav Benes
  2020-09-03 15:35 ` Josh Poimboeuf
  0 siblings, 2 replies; 5+ messages in thread
From: Kristen Carlson Accardi @ 2020-08-12 17:57 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra; +Cc: Kristen Carlson Accardi, linux-kernel

When getting the symbol index number, make sure to use the
extended symbol table information in order to support symbol
index's greater than 64K.

Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
---
 tools/objtool/orc_dump.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c
index fca46e006fc2..cf835069724a 100644
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -74,7 +74,8 @@ int orc_dump(const char *_objname)
 	GElf_Rela rela;
 	GElf_Sym sym;
 	Elf_Data *data, *symtab = NULL, *rela_orc_ip = NULL;
-
+	Elf_Data *xsymtab = NULL;
+	Elf32_Word shndx;
 
 	objname = _objname;
 
@@ -138,6 +139,8 @@ int orc_dump(const char *_objname)
 			orc_ip_addr = sh.sh_addr;
 		} else if (!strcmp(name, ".rela.orc_unwind_ip")) {
 			rela_orc_ip = data;
+		} else if (!strcmp(name, ".symtab_shndx")) {
+			xsymtab = data;
 		}
 	}
 
@@ -157,13 +160,22 @@ int orc_dump(const char *_objname)
 				return -1;
 			}
 
-			if (!gelf_getsym(symtab, GELF_R_SYM(rela.r_info), &sym)) {
-				WARN_ELF("gelf_getsym");
+			if (!gelf_getsymshndx(symtab, xsymtab,
+					      GELF_R_SYM(rela.r_info),
+					      &sym, &shndx)) {
+				WARN_ELF("gelf_getsymshndx");
 				return -1;
 			}
 
 			if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
-				scn = elf_getscn(elf, sym.st_shndx);
+				if ((sym.st_shndx > SHN_UNDEF &&
+				     sym.st_shndx < SHN_LORESERVE) ||
+				    (xsymtab && sym.st_shndx == SHN_XINDEX)) {
+					if (sym.st_shndx != SHN_XINDEX)
+						shndx = sym.st_shndx;
+				}
+
+				scn = elf_getscn(elf, shndx);
 				if (!scn) {
 					WARN_ELF("elf_getscn");
 					return -1;
-- 
2.20.1


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

* Re: [PATCH] objtool: support symtab_shndx during dump
  2020-08-12 17:57 [PATCH] objtool: support symtab_shndx during dump Kristen Carlson Accardi
@ 2020-09-03 11:43 ` Miroslav Benes
  2020-09-03 15:35 ` Josh Poimboeuf
  1 sibling, 0 replies; 5+ messages in thread
From: Miroslav Benes @ 2020-09-03 11:43 UTC (permalink / raw)
  To: Kristen Carlson Accardi; +Cc: Josh Poimboeuf, Peter Zijlstra, linux-kernel

On Wed, 12 Aug 2020, Kristen Carlson Accardi wrote:

> When getting the symbol index number, make sure to use the
> extended symbol table information in order to support symbol
> index's greater than 64K.
> 
> Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>

Reviewed-by: Miroslav Benes <mbenes@suse.cz>

M

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

* Re: [PATCH] objtool: support symtab_shndx during dump
  2020-08-12 17:57 [PATCH] objtool: support symtab_shndx during dump Kristen Carlson Accardi
  2020-09-03 11:43 ` Miroslav Benes
@ 2020-09-03 15:35 ` Josh Poimboeuf
  2020-09-04  7:54   ` Miroslav Benes
  1 sibling, 1 reply; 5+ messages in thread
From: Josh Poimboeuf @ 2020-09-03 15:35 UTC (permalink / raw)
  To: Kristen Carlson Accardi; +Cc: Peter Zijlstra, linux-kernel, Miroslav Benes

On Wed, Aug 12, 2020 at 10:57:11AM -0700, Kristen Carlson Accardi wrote:
> When getting the symbol index number, make sure to use the
> extended symbol table information in order to support symbol
> index's greater than 64K.

"indexes"

>  			if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
> -				scn = elf_getscn(elf, sym.st_shndx);
> +				if ((sym.st_shndx > SHN_UNDEF &&
> +				     sym.st_shndx < SHN_LORESERVE) ||
> +				    (xsymtab && sym.st_shndx == SHN_XINDEX)) {
> +					if (sym.st_shndx != SHN_XINDEX)
> +						shndx = sym.st_shndx;

The sym.st_shndx checks are redundant, if 'sym.st_shndx == SHN_XINDEX'
then 'sym.st_shndx != SHN_XINDEX' can't be true.

Actually I think this can be even further simplified to something like

				if (!shndx)
					shndx = sym.st_shndx;

-- 
Josh


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

* Re: [PATCH] objtool: support symtab_shndx during dump
  2020-09-03 15:35 ` Josh Poimboeuf
@ 2020-09-04  7:54   ` Miroslav Benes
  2020-09-04 14:17     ` Josh Poimboeuf
  0 siblings, 1 reply; 5+ messages in thread
From: Miroslav Benes @ 2020-09-04  7:54 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Kristen Carlson Accardi, Peter Zijlstra, linux-kernel

On Thu, 3 Sep 2020, Josh Poimboeuf wrote:

> On Wed, Aug 12, 2020 at 10:57:11AM -0700, Kristen Carlson Accardi wrote:
> 
> >  			if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
> > -				scn = elf_getscn(elf, sym.st_shndx);
> > +				if ((sym.st_shndx > SHN_UNDEF &&
> > +				     sym.st_shndx < SHN_LORESERVE) ||
> > +				    (xsymtab && sym.st_shndx == SHN_XINDEX)) {
> > +					if (sym.st_shndx != SHN_XINDEX)
> > +						shndx = sym.st_shndx;
> 
> The sym.st_shndx checks are redundant, if 'sym.st_shndx == SHN_XINDEX'
> then 'sym.st_shndx != SHN_XINDEX' can't be true.

It is probably a copy-paste from read_symbols() in elf.c, where the logic 
is different.

> Actually I think this can be even further simplified to something like
> 
> 				if (!shndx)
> 					shndx = sym.st_shndx;

This relies on the fact that gelf_getsymshndx() always initializes shndx, 
no? I think it would be better to initialize it in orc_dump() too. Safer 
and easier to read. It applies to Kristen's patch as well. I missed that.

Miroslav

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

* Re: [PATCH] objtool: support symtab_shndx during dump
  2020-09-04  7:54   ` Miroslav Benes
@ 2020-09-04 14:17     ` Josh Poimboeuf
  0 siblings, 0 replies; 5+ messages in thread
From: Josh Poimboeuf @ 2020-09-04 14:17 UTC (permalink / raw)
  To: Miroslav Benes; +Cc: Kristen Carlson Accardi, Peter Zijlstra, linux-kernel

On Fri, Sep 04, 2020 at 09:54:29AM +0200, Miroslav Benes wrote:
> On Thu, 3 Sep 2020, Josh Poimboeuf wrote:
> 
> > On Wed, Aug 12, 2020 at 10:57:11AM -0700, Kristen Carlson Accardi wrote:
> > 
> > >  			if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
> > > -				scn = elf_getscn(elf, sym.st_shndx);
> > > +				if ((sym.st_shndx > SHN_UNDEF &&
> > > +				     sym.st_shndx < SHN_LORESERVE) ||
> > > +				    (xsymtab && sym.st_shndx == SHN_XINDEX)) {
> > > +					if (sym.st_shndx != SHN_XINDEX)
> > > +						shndx = sym.st_shndx;
> > 
> > The sym.st_shndx checks are redundant, if 'sym.st_shndx == SHN_XINDEX'
> > then 'sym.st_shndx != SHN_XINDEX' can't be true.
> 
> It is probably a copy-paste from read_symbols() in elf.c, where the logic 
> is different.

Yeah.

> > Actually I think this can be even further simplified to something like
> > 
> > 				if (!shndx)
> > 					shndx = sym.st_shndx;
> 
> This relies on the fact that gelf_getsymshndx() always initializes shndx, 
> no? I think it would be better to initialize it in orc_dump() too. Safer 
> and easier to read. It applies to Kristen's patch as well. I missed that.

Agreed.

-- 
Josh


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

end of thread, other threads:[~2020-09-04 14:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 17:57 [PATCH] objtool: support symtab_shndx during dump Kristen Carlson Accardi
2020-09-03 11:43 ` Miroslav Benes
2020-09-03 15:35 ` Josh Poimboeuf
2020-09-04  7:54   ` Miroslav Benes
2020-09-04 14:17     ` Josh Poimboeuf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).