-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm-objdump][macho] Add support for ObjC relative method lists (#85477
) For Mach-O, ld64 supports the -fobjc-relative-method-lists flag which changes the format in which method lists are generated. The format uses delta encoding vs the original direct-pointer encoding. This change adds support to llvm-objdump and llvm-otool for decoding/dumping of method lists in the delta format. Previously, if a binary with this information format was passed to the tooling, it would output invalid information, trying to parse the delta lists as pointer lists. After this change, the tooling will output correct information if a binary in this format is encountered. The output format is closest feasible match to XCode 15.1's otool output. Tests are included for both 32bit and 64bit binaries. The code style was matched as close as possible to existing implementation of parsing non-delta method lists. Diff between llvm-objdump and XCode 15.1 otool: ![image](https://github.com/llvm/llvm-project/assets/103613512/2277e3ff-d59c-4fff-b93a-e0587ee740a6) Note: This is a retry of this PR: #84250 On the original PR, the armv7+armv8 builds were failing due to absolute offsets being different. Co-authored-by: Alex B <alexborcan@meta.com>
- Loading branch information
Showing
4 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
Binary file added
BIN
+3.13 KB
llvm/test/tools/llvm-objdump/MachO/AArch64/Inputs/rel-method-lists-arm64.dylib
Binary file not shown.
Binary file added
BIN
+2.65 KB
llvm/test/tools/llvm-objdump/MachO/AArch64/Inputs/rel-method-lists-arm64_32.dylib
Binary file not shown.
86 changes: 86 additions & 0 deletions
86
llvm/test/tools/llvm-objdump/MachO/AArch64/macho-relative-method-lists.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
RUN: llvm-objdump --macho --objc-meta-data %p/Inputs/rel-method-lists-arm64_32.dylib | FileCheck %s --check-prefix=CHK32 | ||
RUN: llvm-otool -ov %p/Inputs/rel-method-lists-arm64_32.dylib | FileCheck %s --check-prefix=CHK32 | ||
|
||
RUN: llvm-objdump --macho --objc-meta-data %p/Inputs/rel-method-lists-arm64.dylib | FileCheck %s --check-prefix=CHK64 | ||
RUN: llvm-otool -ov %p/Inputs/rel-method-lists-arm64.dylib | FileCheck %s --check-prefix=CHK64 | ||
|
||
CHK32: baseMethods 0x660 (struct method_list_t *) | ||
CHK32-NEXT: entsize 12 (relative) | ||
CHK32-NEXT: count 3 | ||
CHK32-NEXT: name 0x144 (0x{{[0-9a-f]*}}) instance_method_00 | ||
CHK32-NEXT: types 0x91 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffff18 (0x{{[0-9a-f]*}}) -[MyClass instance_method_00] | ||
CHK32-NEXT: name 0x13c (0x{{[0-9a-f]*}}) instance_method_01 | ||
CHK32-NEXT: types 0x85 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffff28 (0x{{[0-9a-f]*}}) -[MyClass instance_method_01] | ||
CHK32-NEXT: name 0x134 (0x{{[0-9a-f]*}}) instance_method_02 | ||
CHK32-NEXT: types 0x79 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffff38 (0x{{[0-9a-f]*}}) -[MyClass instance_method_02] | ||
|
||
CHK32: baseMethods 0x630 (struct method_list_t *) | ||
CHK32-NEXT: entsize 12 (relative) | ||
CHK32-NEXT: count 3 | ||
CHK32-NEXT: name 0x180 (0x{{[0-9a-f]*}}) class_method_00 | ||
CHK32-NEXT: types 0xc1 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffff9c (0x{{[0-9a-f]*}}) +[MyClass class_method_00] | ||
CHK32-NEXT: name 0x178 (0x{{[0-9a-f]*}}) class_method_01 | ||
CHK32-NEXT: types 0xb5 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffffac (0x{{[0-9a-f]*}}) +[MyClass class_method_01] | ||
CHK32-NEXT: name 0x170 (0x{{[0-9a-f]*}}) class_method_02 | ||
CHK32-NEXT: types 0xa9 (0x{{[0-9a-f]*}}) v8@0:4 | ||
CHK32-NEXT: imp 0xffffffbc (0x{{[0-9a-f]*}}) +[MyClass class_method_02] | ||
|
||
CHK64: baseMethods 0x6e0 (struct method_list_t *) | ||
CHK64-NEXT: entsize 12 (relative) | ||
CHK64-NEXT: count 3 | ||
CHK64-NEXT: name 0x188 (0x{{[0-9a-f]*}}) instance_method_00 | ||
CHK64-NEXT: types 0x91 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffffa8 (0x{{[0-9a-f]*}}) -[MyClass instance_method_00] | ||
CHK64-NEXT: name 0x184 (0x{{[0-9a-f]*}}) instance_method_01 | ||
CHK64-NEXT: types 0x85 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffffa0 (0x{{[0-9a-f]*}}) -[MyClass instance_method_01] | ||
CHK64-NEXT: name 0x180 (0x{{[0-9a-f]*}}) instance_method_02 | ||
CHK64-NEXT: types 0x79 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffff98 (0x{{[0-9a-f]*}}) -[MyClass instance_method_02] | ||
|
||
CHK64: baseMethods 0x6b0 (struct method_list_t *) | ||
CHK64-NEXT: entsize 12 (relative) | ||
CHK64-NEXT: count 3 | ||
CHK64-NEXT: name 0x1d0 (0x{{[0-9a-f]*}}) class_method_00 | ||
CHK64-NEXT: types 0xc1 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffffe4 (0x{{[0-9a-f]*}}) +[MyClass class_method_00] | ||
CHK64-NEXT: name 0x1cc (0x{{[0-9a-f]*}}) class_method_01 | ||
CHK64-NEXT: types 0xb5 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffffdc (0x{{[0-9a-f]*}}) +[MyClass class_method_01] | ||
CHK64-NEXT: name 0x1c8 (0x{{[0-9a-f]*}}) class_method_02 | ||
CHK64-NEXT: types 0xa9 (0x{{[0-9a-f]*}}) v16@0:8 | ||
CHK64-NEXT: imp 0xffffffd4 (0x{{[0-9a-f]*}}) +[MyClass class_method_02] | ||
|
||
######## Generate rel-method-lists-arm64.dylib ######## | ||
// clang -c main.mm -o main.o -target arm64-apple-macos -arch arm64 | ||
// ld64.ld64 -dylib -demangle -dynamic main.o -o rel-method-lists-arm64.dylib -syslibroot MacOSX14.2.sdk -segalign 0x10 -objc_relative_method_lists | ||
|
||
######## Generate rel-method-lists-arm64_32.dylib ######## | ||
// clang -c main.mm -o main.o -target arm64_32-apple-watchos -arch arm64_32 | ||
// ld64.ld64 -dylib -demangle -dynamic main.o -o rel-method-lists-arm64_32.dylib -syslibroot WatchOS.sdk -segalign 0x10 -objc_relative_method_lists | ||
|
||
// ~~~~~~~~~~~~~~~~~~~~~~~~~ main.mm ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
__attribute__((objc_root_class)) | ||
@interface MyClass | ||
- (void)instance_method_00; | ||
- (void)instance_method_01; | ||
- (void)instance_method_02; | ||
+ (void)class_method_00; | ||
+ (void)class_method_01; | ||
+ (void)class_method_02; | ||
@end | ||
@implementation MyClass | ||
- (void)instance_method_00 {} | ||
- (void)instance_method_01 {} | ||
- (void)instance_method_02 {} | ||
+ (void)class_method_00 {} | ||
+ (void)class_method_01 {} | ||
+ (void)class_method_02 {} | ||
@end | ||
void *_objc_empty_cache; | ||
void *_objc_empty_vtable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alx32 Hi, this test is failing on AIX too, could you take a look please?
https://lab.llvm.org/buildbot/#/builders/178/builds/7028/steps/7/logs/FAIL__LLVM__macho-relative-method-lists_test
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jakeegan - this commit was landed on Mar14 as #84250.
Then backed out later that day because of the armv7/armv8 test failures.
Then landed again as #85477
The failure from the link is a build on
229640343e400394b315c6798c7c19e8a9bd188c
- from Mar 14th when the problematic version of the commit was checked in.This failure should be fixed currently. Are we seeing any recent failures after #85477 ?
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for investigating. Yes we're still seeing the failure after #85477. I just checked the most recent build (here: https://lab.llvm.org/buildbot/#/builders/214/builds/11630) and it contains that commit. I also tried a clean build, but still see the failure.
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a new failure, thanks for pointing this out. Are there instructions how to build / run "clang-ppc64-aix" platform ? What type of machines are these ?
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The machine is an AIX operating system running on powerpc hardware. I could give you access to an AIX machine and give you instructions to build. In the meantime I'll XFAIL the test to unblock the bot.
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that would be great - XFAIL-ing and getting access to an AIX machine.
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the obvious fix: #85778
Should I just merge this or would you be able to test or give me access on an AIX machine ?
9d5edfd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alx32 Sorry to get back to you late. It seems it's already been merged in. Thanks a lot for fixing it!