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: <168629685285.404.18154288626119314332.tip-bot2@tip-bot2>
Date:   Fri, 09 Jun 2023 07:47:32 -0000
From:   "tip-bot2 for Josh Poimboeuf" <tip-bot2@...utronix.de>
To:     linux-tip-commits@...r.kernel.org
Cc:     Josh Poimboeuf <jpoimboe@...nel.org>, x86@...nel.org,
        linux-kernel@...r.kernel.org
Subject: [tip: objtool/core] objtool: Allocate relocs in advance for new rela sections

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     e0a9349b4c590145c6a83e6c9f7701cec42debbd
Gitweb:        https://git.kernel.org/tip/e0a9349b4c590145c6a83e6c9f7701cec42debbd
Author:        Josh Poimboeuf <jpoimboe@...nel.org>
AuthorDate:    Tue, 30 May 2023 10:21:03 -07:00
Committer:     Josh Poimboeuf <jpoimboe@...nel.org>
CommitterDate: Wed, 07 Jun 2023 10:03:20 -07:00

objtool: Allocate relocs in advance for new rela sections

Similar to read_relocs(), allocate the reloc structs all together in an
array rather than allocating them one at a time.

Link: https://lore.kernel.org/r/5332d845c5a2d6c2d052075b381bfba8bcb67ed5.1685464332.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@...nel.org>
---
 tools/objtool/elf.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 8d53f18..5f69d45 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -814,7 +814,7 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec,
 				    unsigned long offset, struct symbol *sym,
 				    s64 addend, unsigned int type)
 {
-	struct reloc *reloc;
+	struct reloc *reloc, empty = { 0 };
 
 	if (reloc_idx >= rsec->sh.sh_size / elf_rela_size(elf)) {
 		WARN("%s: bad reloc_idx %u for %s with size 0x%lx",
@@ -822,12 +822,13 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec,
 		return NULL;
 	}
 
-	reloc = malloc(sizeof(*reloc));
-	if (!reloc) {
-		perror("malloc");
+	reloc = &rsec->reloc_data[reloc_idx];
+
+	if (memcmp(reloc, &empty, sizeof(empty))) {
+		WARN("%s: %s: reloc %d already initialized!",
+		     __func__, rsec->name, reloc_idx);
 		return NULL;
 	}
-	memset(reloc, 0, sizeof(*reloc));
 
 	reloc->idx = reloc_idx;
 	reloc->sec = rsec;
@@ -1185,6 +1186,13 @@ static struct section *elf_create_rela_section(struct elf *elf,
 	rsec->sh.sh_info = sec->idx;
 	rsec->sh.sh_flags = SHF_INFO_LINK;
 
+	rsec->reloc_data = calloc(rsec->sh.sh_size / rsec->sh.sh_entsize,
+				  sizeof(struct reloc));
+	if (!rsec->reloc_data) {
+		perror("calloc");
+		return NULL;
+	}
+
 	sec->rsec = rsec;
 	rsec->base = sec;
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ