Skip to content

Commit 608316d

Browse files
committed
[dsymutil] Fix offset calculation for universal binaries
The Mach-O file format uses 32-bit values to encodes offsets which they cannot exceed UIN32_MAX (4GB). The Mach-O file itself can be larger than 4GB as long as none of the offsets fall within this limit. For universal binaries, dsymutil determines if the offset is going to exceed the 4GB limit by computing the size of the header and adding it to the size of all the slices. This is incorrect because it computes the end offset of the final slice. For the purpose of the 4GB limit, only the starting offset matters. The size of the last slice is irrelevant as long as it itself is a valid Mach-O. rdar://104435018 Differential revision: https://reviews.llvm.org/D145637 (cherry picked from commit 244a6ac)
1 parent 9a3cc16 commit 608316d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/Support/CrashRecoveryContext.h"
3737
#include "llvm/Support/FileCollector.h"
3838
#include "llvm/Support/FileSystem.h"
39+
#include "llvm/Support/FormatVariadic.h"
3940
#include "llvm/Support/InitLLVM.h"
4041
#include "llvm/Support/Path.h"
4142
#include "llvm/Support/TargetSelect.h"
@@ -796,12 +797,14 @@ int dsymutil_main(int argc, char **argv) {
796797
ErrorOr<vfs::Status> stat = Options.LinkOpts.VFS->status(File.path());
797798
if (!stat)
798799
break;
799-
FileOffset += stat->getSize();
800800
if (FileOffset > UINT32_MAX) {
801-
WithColor::error() << "the universal binary has a slice with an "
802-
"offset exceeds 4GB and will produce an invalid Mach-O file.";
801+
WithColor::error() << formatv(
802+
"the universal binary has a slice with a starting offset ({0:x}) "
803+
"that exceeds 4GB and will produce an invalid Mach-O file.",
804+
FileOffset);
803805
return EXIT_FAILURE;
804806
}
807+
FileOffset += stat->getSize();
805808
}
806809
if (!MachOUtils::generateUniversalBinary(TempFiles,
807810
OutputLocationOrErr->DWARFFile,

0 commit comments

Comments
 (0)