Which slice will be picked by an iPhone
Asked Answered
S

5

9

I have an .ipa which has arm64 and armv7 slices in it. If I run it on a iDevice which supports both arm64 and armv7 which slice will be picked by the runtime ?

Can I see somewhere by printing NSLog or some way to understand that runtime has picked slice arm64 ?

Saadi answered 19/1, 2017 at 7:49 Comment(1)
Nice reading.Analogous
C
1

You could try this way. You will have to add more options of cpu_type_t.

func getCPUType() -> String {

var size: size_t = 0
var type: cpu_type_t = 0
var subtype: cpu_subtype_t = 0
size = MemoryLayout<cpu_type_t>.size;
sysctlbyname("hw.cputype", &type, &size, nil, 0);

size = MemoryLayout<cpu_subtype_t>.size;
sysctlbyname("hw.cpusubtype", &subtype, &size, nil, 0);

// values for cputype and cpusubtype defined in mach/machine.h
var cpu = ""
if (type == CPU_TYPE_X86)
{
    cpu += "x86"

} else if (type == CPU_TYPE_VAX) {
    cpu += "vax"

} else if (type == CPU_TYPE_ARM) {
    cpu += "ARM"
    switch(subtype)
    {
    case CPU_SUBTYPE_ARM_V7:
        cpu += "V7"
        break;
        // ...
    default: break
    }
}

return cpu
}

Edited: First try with "hw.cpufamily"

sysctlbyname("hw.cpufamily", &type, &size, nil, 0);
Corcoran answered 31/1, 2017 at 13:7 Comment(1)
Will this always work? I think this method could determine what the CPU is but not necessarily what the operational data model is for a program running on a CPU that could do either. And that seems to be part of what the OP is asking.Eugenioeugenius
H
1

If your app is downloaded through App Store with byte code enabled, then iTunes connect will let an iOS device to download the appropriate binary according to your device architecture.

if you are deploying through Xcode check for this option: enter image description here it will only compile according to your iOS device architecture.

if you have that option as NO then you could test which binary architecture is running:

if(sizeof(int*) == 4)
    NSLog(@"32 bit arch");
else if(sizeof(int*) == 8)
    NSLog(@"64 bit arch");
Habsburg answered 29/1, 2017 at 9:52 Comment(0)
E
1

According to Apple:

  1. "The compiler defines the __LP64__ macro when compiling for the 64-bit runtime", and
  2. "The size of pointers increased from 4 bytes to 8 bytes" (when going from ILP32 to LP64).

If you were interested in determining the architecture at compile-time, essentially the following code comes up (from googling):

#if __LP64__
// Being compiled for LP64 (64-bit arm64)
#else
// Being compiled for ILP32 (32-bit armv7)
#endif

As you're asking for a run-time test however, using the size-of-pointer determining technique (as affirmed per the Apple guide page I linked above) is a way to do this. The code suggested by Manish or Hashmat shows how.

Eugenioeugenius answered 30/1, 2017 at 21:7 Comment(0)
C
1

You could try this way. You will have to add more options of cpu_type_t.

func getCPUType() -> String {

var size: size_t = 0
var type: cpu_type_t = 0
var subtype: cpu_subtype_t = 0
size = MemoryLayout<cpu_type_t>.size;
sysctlbyname("hw.cputype", &type, &size, nil, 0);

size = MemoryLayout<cpu_subtype_t>.size;
sysctlbyname("hw.cpusubtype", &subtype, &size, nil, 0);

// values for cputype and cpusubtype defined in mach/machine.h
var cpu = ""
if (type == CPU_TYPE_X86)
{
    cpu += "x86"

} else if (type == CPU_TYPE_VAX) {
    cpu += "vax"

} else if (type == CPU_TYPE_ARM) {
    cpu += "ARM"
    switch(subtype)
    {
    case CPU_SUBTYPE_ARM_V7:
        cpu += "V7"
        break;
        // ...
    default: break
    }
}

return cpu
}

Edited: First try with "hw.cpufamily"

sysctlbyname("hw.cpufamily", &type, &size, nil, 0);
Corcoran answered 31/1, 2017 at 13:7 Comment(1)
Will this always work? I think this method could determine what the CPU is but not necessarily what the operational data model is for a program running on a CPU that could do either. And that seems to be part of what the OP is asking.Eugenioeugenius
A
1

I saw this question earlier, which I believe is relevant if you look at the comments on the question:

Xcode 6.3 builds all swift files twice

In the case of the linked question, although outdated, the answer is both. Each file will be built twice, and this can be manually changed within the build settings (Build Active Architecture Only).

Angelita answered 31/1, 2017 at 16:54 Comment(0)
S
0

How about using this code to find out?

#if TARGET_OS_SIMULATOR


#else
if(sizeof(void *) == 4)
{
  NSLog(@" This is a 32 bit architecture so most probably this armv7 ");
}
else if (sizeof(void *) == 8)
{
  NSLog(@" This is a 64 bit architecture so most probably this is arm64 ");
}
else
{
  NSLog(@" Unrecognized architecture ");
}
#endif
Sungsungari answered 30/1, 2017 at 2:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.