[llvm] [MachO] Fix copy-paste condition in bounds check (PR #100176)

Daniel Bertalan via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 03:25:21 PDT 2024


https://github.com/BertalanD updated https://github.com/llvm/llvm-project/pull/100176

>From 65bf6d58531147d991dc6e58772cd3053ab61eb1 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani at danielbertalan.dev>
Date: Tue, 23 Jul 2024 20:20:59 +0200
Subject: [PATCH 1/2] [MachO] Fix copy-paste condition in bounds check

I made this thinko in 686d8ce.

Note that that change was never intended to be permanent, and served as
a quick stopgap to facilitate testing chained fixups in LLD before Apple
upstreamed their implementation. That has not yet happened in the two
years since.

Fixes #90662
Fixes #87203
---
 llvm/lib/Object/MachOObjectFile.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 812b2c00ba699..2a17b496fd62b 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -5193,7 +5193,7 @@ MachOObjectFile::getDyldChainedFixupTargets() const {
   const char *Symbols = Contents + Header.symbols_offset;
   const char *SymbolsEnd = Contents + DyldChainedFixups.datasize;
 
-  if (ImportsEnd > Symbols)
+  if (ImportsEnd > SymbolsEnd)
     return malformedError("bad chained fixups: imports end " +
                           Twine(ImportsEndOffset) + " extends past end " +
                           Twine(DyldChainedFixups.datasize));

>From 800b5384133aee6f2234e528bf1f246bd07d17e7 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani at danielbertalan.dev>
Date: Wed, 31 Jul 2024 12:20:47 +0200
Subject: [PATCH 2/2] Remove the more lax check instead

---
 llvm/lib/Object/MachOObjectFile.cpp | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index 2a17b496fd62b..ff55a847c3432 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -5193,11 +5193,6 @@ MachOObjectFile::getDyldChainedFixupTargets() const {
   const char *Symbols = Contents + Header.symbols_offset;
   const char *SymbolsEnd = Contents + DyldChainedFixups.datasize;
 
-  if (ImportsEnd > SymbolsEnd)
-    return malformedError("bad chained fixups: imports end " +
-                          Twine(ImportsEndOffset) + " extends past end " +
-                          Twine(DyldChainedFixups.datasize));
-
   if (ImportsEnd > Symbols)
     return malformedError("bad chained fixups: imports end " +
                           Twine(ImportsEndOffset) + " overlaps with symbols");



More information about the llvm-commits mailing list