lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1690272910-11869-6-git-send-email-yangtiezhu@loongson.cn>
Date:   Tue, 25 Jul 2023 16:15:09 +0800
From:   Tiezhu Yang <yangtiezhu@...ngson.cn>
To:     Josh Poimboeuf <jpoimboe@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Huacai Chen <chenhuacai@...nel.org>
Cc:     loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
        loongson-kernel@...ts.loongnix.cn
Subject: [PATCH v1 5/6] objtool: Add skipped member in struct reloc

There exist multiple relocation types in one location, such as a pair of
R_LARCH_ADD32 and R_LARCH_SUB32 in section .rela.discard.unreachable and
.rela.discard.reachable on LoongArch.

Here is an example:

$ readelf -rW init/main.o

Relocation section '.rela.discard.unreachable' at offset 0x3e20 contains 2 entries:
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000000000  0000000a00000032 R_LARCH_ADD32          0000000000000000 .init.text + 230
0000000000000000  0000001a00000037 R_LARCH_SUB32          0000000000000000 L0^A + 0

Relocation section '.rela.discard.reachable' at offset 0x4a00 contains 6 entries:
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000000000  0000000a00000032 R_LARCH_ADD32          0000000000000000 .init.text + ae0
0000000000000000  0000002800000037 R_LARCH_SUB32          0000000000000000 L0^A + 0
0000000000000004  0000000a00000032 R_LARCH_ADD32          0000000000000000 .init.text + b88
0000000000000004  0000002b00000037 R_LARCH_SUB32          0000000000000004 L0^A + 0
0000000000000008  0000000200000032 R_LARCH_ADD32          0000000000000000 .text + 23c
0000000000000008  0000002e00000037 R_LARCH_SUB32          0000000000000008 L0^A + 0

In order to silence the related objtool warnings, add skipped member
in struct reloc to record and skip the latter relocation.

Co-developed-by: Jinyang He <hejinyang@...ngson.cn>
Signed-off-by: Jinyang He <hejinyang@...ngson.cn>
Co-developed-by: Youling Tang <tangyouling@...ngson.cn>
Signed-off-by: Youling Tang <tangyouling@...ngson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
 tools/objtool/check.c               | 4 ++++
 tools/objtool/elf.c                 | 6 ++++++
 tools/objtool/include/objtool/elf.h | 1 +
 3 files changed, 11 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 9e5e462..602318e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -594,6 +594,8 @@ static int add_dead_ends(struct objtool_file *file)
 		goto reachable;
 
 	for_each_reloc(rsec, reloc) {
+		if (reloc->skipped)
+			continue;
 
 		if (reloc->sym->type != STT_SECTION) {
 			WARN("unexpected relocation symbol type in %s", rsec->name);
@@ -633,6 +635,8 @@ static int add_dead_ends(struct objtool_file *file)
 		return 0;
 
 	for_each_reloc(rsec, reloc) {
+		if (reloc->skipped)
+			continue;
 
 		if (reloc->sym->type != STT_SECTION) {
 			WARN("unexpected relocation symbol type in %s", rsec->name);
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index d420b5d..bd950d4 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -975,6 +975,12 @@ static int read_relocs(struct elf *elf)
 				return -1;
 			}
 
+			if (!(strcmp(rsec->name, ".rela.discard.unreachable")) ||
+			    !(strcmp(rsec->name, ".rela.discard.reachable"))) {
+				if (reloc->sym->type != STT_SECTION)
+					reloc->skipped = true;
+			}
+
 			elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc));
 			reloc->sym_next_reloc = sym->relocs;
 			sym->relocs = reloc;
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index c532d70..4141837 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -75,6 +75,7 @@ struct reloc {
 	struct section *sec;
 	struct symbol *sym;
 	struct reloc *sym_next_reloc;
+	bool skipped;
 };
 
 struct elf {
-- 
2.1.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ