[PATCH v2 pahole 6/7] loaders: record CU's endianness in dwarf/btf/ctf loaders

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch records for each CU whether it's in little-endian or
big-endian data format. This flag will be used in subsequent commits to
adjust bit offsets where necessary, to make them uniform across
endianness. This patch doesn't have any effect on pahole's output.

Signed-off-by: Andrii Nakryiko <andriin@xxxxxx>
---
 btf_loader.c   |  1 +
 ctf_loader.c   |  1 +
 dwarf_loader.c | 12 ++++++++++++
 dwarves.h      |  1 +
 4 files changed, 15 insertions(+)

diff --git a/btf_loader.c b/btf_loader.c
index e98505b..06fd037 100644
--- a/btf_loader.c
+++ b/btf_loader.c
@@ -538,6 +538,7 @@ int btf_elf__load_file(struct cus *cus, struct conf_load *conf, const char *file
 
 	cu->language = LANG_C;
 	cu->uses_global_strings = false;
+	cu->little_endian = !btfe->is_big_endian;
 	cu->dfops = &btf_elf__ops;
 	cu->priv = btfe;
 	btfe->priv = cu;
diff --git a/ctf_loader.c b/ctf_loader.c
index 68479e2..1664be1 100644
--- a/ctf_loader.c
+++ b/ctf_loader.c
@@ -734,6 +734,7 @@ int ctf__load_file(struct cus *cus, struct conf_load *conf,
 
 	cu->language = LANG_C;
 	cu->uses_global_strings = false;
+	cu->little_endian = state->ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
 	cu->dfops = &ctf__ops;
 	cu->priv = state;
 	state->priv = cu;
diff --git a/dwarf_loader.c b/dwarf_loader.c
index ee9d7ad..888a054 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -2243,6 +2243,12 @@ static int cus__load_debug_types(struct cus *cus, struct conf_load *conf,
 			cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
 			cu->has_addr_info = conf ? conf->get_addr_info : 0;
 
+			GElf_Ehdr ehdr;
+			if (gelf_getehdr(elf, &ehdr) == NULL) {
+				return DWARF_CB_ABORT;
+			}
+			cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
+
 			dwarf_cu__init(dcup);
 			dcup->cu = cu;
 			/* Funny hack.  */
@@ -2324,6 +2330,12 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf,
 		cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
 		cu->has_addr_info = conf ? conf->get_addr_info : 0;
 
+		GElf_Ehdr ehdr;
+		if (gelf_getehdr(elf, &ehdr) == NULL) {
+			return DWARF_CB_ABORT;
+		}
+		cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
+		
 		struct dwarf_cu dcu;
 
 		dwarf_cu__init(&dcu);
diff --git a/dwarves.h b/dwarves.h
index f65dbe2..e39871f 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -200,6 +200,7 @@ struct cu {
 	uint8_t		 extra_dbg_info:1;
 	uint8_t		 has_addr_info:1;
 	uint8_t		 uses_global_strings:1;
+	uint8_t		 little_endian:1;
 	uint16_t	 language;
 	unsigned long	 nr_inline_expansions;
 	size_t		 size_inline_expansions;
-- 
2.17.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux