UPDATE
After clarifing with OP that extension of __TEXT.__objc_methname
would happen during Mach-O post processing of an existing executable I had a fresh look on the problem.
Another take would be to create a new load command LC_SEGMENT_64
with a new __TEXT_EXEC.__objc_methname
segment / section entry (normally __TEXT_EXEC
is used for some kernel stuff but essentially it's the same thing as __TEXT
). Here's a quick POC to ilustrate the concept:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
printf("%lx",[NSObject new]);
}
return 0;
}
Compile like this:
gcc main.m -c -o main.o
ld main.o -rename_section __TEXT __objc_methname __TEXT_EXEC __objc_methname -lobjc -lc
Interestingly only ld
up to High Sierra 10.14.6 generates __TEXT.__objc_methname
, no trace of it on Catalina, it's done differently.
UPDATE2.
Playing around with it, I noticed execution rights for __TEXT
segment (and __TEXT_EXEC
for that matter) are not required for __objc_methname
to work.
Even better specific segment & section names are not required:
I could pull off:
__DATA.__objc_methname
__DATA_CONST.__objc_methname
__ARBITRARY.__arbitrary
or in my case last __DATA
section
__DATA.__objc_classrefs
where the original the data got concatenated by the selector name.
It's all fine as long as a proper null terminated C-string with the selector name is there. If I intentionally break the "new\0" in hex editor or MachOView I'll get
"+[NSObject ne]: unrecognized selector sent to instance ..."
upon launching my POC executable so the value is used for sure.
So to sum __TEXT.__objc_methname
section itself is likely some debugger hint made by the linker. The app runtime seems to only need selector names as char*
anywhere in memory.