Skip to content

Commit 1f4717b

Browse files
author
git apple-llvm automerger
committed
Merge commit '56d19e7e0118' from apple/stable/20200714 into swift/main
2 parents 006268a + 56d19e7 commit 1f4717b

File tree

8 files changed

+123
-48
lines changed

8 files changed

+123
-48
lines changed

lldb/tools/debugserver/source/DNB.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,19 +1723,52 @@ nub_bool_t DNBSetArchitecture(const char *arch) {
17231723
if (arch && arch[0]) {
17241724
if (strcasecmp(arch, "i386") == 0)
17251725
return DNBArchProtocol::SetArchitecture(CPU_TYPE_I386);
1726-
else if ((strcasecmp(arch, "x86_64") == 0) ||
1727-
(strcasecmp(arch, "x86_64h") == 0))
1728-
return DNBArchProtocol::SetArchitecture(CPU_TYPE_X86_64);
1729-
else if (strstr(arch, "arm64_32") == arch ||
1726+
else if (strcasecmp(arch, "x86_64") == 0)
1727+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_X86_64,
1728+
CPU_SUBTYPE_X86_64_ALL);
1729+
else if (strcasecmp(arch, "x86_64h") == 0)
1730+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_X86_64,
1731+
CPU_SUBTYPE_X86_64_H);
1732+
else if (strstr(arch, "arm64_32") == arch ||
17301733
strstr(arch, "aarch64_32") == arch)
17311734
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64_32);
17321735
else if (strstr(arch, "arm64e") == arch)
1733-
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64);
1734-
else if (strstr(arch, "arm64") == arch || strstr(arch, "armv8") == arch ||
1735-
strstr(arch, "aarch64") == arch)
1736-
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64);
1736+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64,
1737+
CPU_SUBTYPE_ARM64E);
1738+
else if (strstr(arch, "arm64") == arch || strstr(arch, "aarch64") == arch)
1739+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64,
1740+
CPU_SUBTYPE_ARM64_ALL);
1741+
else if (strstr(arch, "armv8") == arch)
1742+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM64,
1743+
CPU_SUBTYPE_ARM64_V8);
1744+
else if (strstr(arch, "armv7em") == arch)
1745+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1746+
CPU_SUBTYPE_ARM_V7EM);
1747+
else if (strstr(arch, "armv7m") == arch)
1748+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1749+
CPU_SUBTYPE_ARM_V7M);
1750+
else if (strstr(arch, "armv7k") == arch)
1751+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1752+
CPU_SUBTYPE_ARM_V7K);
1753+
else if (strstr(arch, "armv7s") == arch)
1754+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1755+
CPU_SUBTYPE_ARM_V7S);
1756+
else if (strstr(arch, "armv7") == arch)
1757+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7);
1758+
else if (strstr(arch, "armv6m") == arch)
1759+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1760+
CPU_SUBTYPE_ARM_V6M);
1761+
else if (strstr(arch, "armv6") == arch)
1762+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6);
1763+
else if (strstr(arch, "armv5") == arch)
1764+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1765+
CPU_SUBTYPE_ARM_V5TEJ);
1766+
else if (strstr(arch, "armv4t") == arch)
1767+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1768+
CPU_SUBTYPE_ARM_V4T);
17371769
else if (strstr(arch, "arm") == arch)
1738-
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM);
1770+
return DNBArchProtocol::SetArchitecture(CPU_TYPE_ARM,
1771+
CPU_SUBTYPE_ARM_ALL);
17391772
}
17401773
return false;
17411774
}

lldb/tools/debugserver/source/DNBArch.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
typedef std::map<uint32_t, DNBArchPluginInfo> CPUPluginInfoMap;
2222

2323
static uint32_t g_current_cpu_type = 0;
24+
static uint32_t g_current_cpu_subtype = 0;
2425
CPUPluginInfoMap g_arch_plugins;
2526

2627
static const DNBArchPluginInfo *GetArchInfo() {
@@ -31,15 +32,17 @@ static const DNBArchPluginInfo *GetArchInfo() {
3132
return NULL;
3233
}
3334

34-
uint32_t DNBArchProtocol::GetArchitecture() { return g_current_cpu_type; }
35+
uint32_t DNBArchProtocol::GetCPUType() { return g_current_cpu_type; }
36+
uint32_t DNBArchProtocol::GetCPUSubType() { return g_current_cpu_subtype; }
3537

36-
bool DNBArchProtocol::SetArchitecture(uint32_t cpu_type) {
38+
bool DNBArchProtocol::SetArchitecture(uint32_t cpu_type, uint32_t cpu_subtype) {
3739
g_current_cpu_type = cpu_type;
40+
g_current_cpu_subtype = cpu_subtype;
3841
bool result = g_arch_plugins.find(g_current_cpu_type) != g_arch_plugins.end();
39-
DNBLogThreadedIf(
40-
LOG_PROCESS,
41-
"DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x) => %i",
42-
cpu_type, result);
42+
DNBLogThreadedIf(LOG_PROCESS,
43+
"DNBArchProtocol::SetDefaultArchitecture (cpu_type=0x%8.8x, "
44+
"cpu_subtype=0x%8.8x) => %i",
45+
cpu_type, cpu_subtype, result);
4346
return result;
4447
}
4548

lldb/tools/debugserver/source/DNBArch.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class DNBArchProtocol {
4949

5050
static void RegisterArchPlugin(const DNBArchPluginInfo &arch_info);
5151

52-
static uint32_t GetArchitecture();
52+
static uint32_t GetCPUType();
53+
static uint32_t GetCPUSubType();
5354

54-
static bool SetArchitecture(uint32_t cpu_type);
55+
static bool SetArchitecture(uint32_t cpu_type, uint32_t cpu_subtype = 0);
5556

5657
DNBArchProtocol() : m_save_id(0) {}
5758

lldb/tools/debugserver/source/MacOSX/MachProcess.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class MachProcess {
9090
char const *envp[],
9191
MachProcess *process, DNBError &err);
9292
static pid_t PosixSpawnChildForPTraceDebugging(
93-
const char *path, cpu_type_t cpu_type, char const *argv[],
94-
char const *envp[], const char *working_directory, const char *stdin_path,
95-
const char *stdout_path, const char *stderr_path, bool no_stdio,
96-
MachProcess *process, int disable_aslr, DNBError &err);
93+
const char *path, cpu_type_t cpu_type, cpu_subtype_t cpu_subtype,
94+
char const *argv[], char const *envp[], const char *working_directory,
95+
const char *stdin_path, const char *stdout_path, const char *stderr_path,
96+
bool no_stdio, MachProcess *process, int disable_aslr, DNBError &err);
9797
nub_addr_t GetDYLDAllImageInfosAddress();
9898
static const void *PrepareForAttach(const char *path,
9999
nub_launch_flavor_t launch_flavor,

lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,9 +3148,9 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
31483148

31493149
case eLaunchFlavorPosixSpawn:
31503150
m_pid = MachProcess::PosixSpawnChildForPTraceDebugging(
3151-
path, DNBArchProtocol::GetArchitecture(), argv, envp, working_directory,
3152-
stdin_path, stdout_path, stderr_path, no_stdio, this, disable_aslr,
3153-
launch_err);
3151+
path, DNBArchProtocol::GetCPUType(), DNBArchProtocol::GetCPUSubType(),
3152+
argv, envp, working_directory, stdin_path, stdout_path, stderr_path,
3153+
no_stdio, this, disable_aslr, launch_err);
31543154
break;
31553155

31563156
default:
@@ -3210,10 +3210,10 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
32103210
}
32113211

32123212
pid_t MachProcess::PosixSpawnChildForPTraceDebugging(
3213-
const char *path, cpu_type_t cpu_type, char const *argv[],
3214-
char const *envp[], const char *working_directory, const char *stdin_path,
3215-
const char *stdout_path, const char *stderr_path, bool no_stdio,
3216-
MachProcess *process, int disable_aslr, DNBError &err) {
3213+
const char *path, cpu_type_t cpu_type, cpu_subtype_t cpu_subtype,
3214+
char const *argv[], char const *envp[], const char *working_directory,
3215+
const char *stdin_path, const char *stdout_path, const char *stderr_path,
3216+
bool no_stdio, MachProcess *process, int disable_aslr, DNBError &err) {
32173217
posix_spawnattr_t attr;
32183218
short flags;
32193219
DNBLogThreadedIf(LOG_PROCESS,
@@ -3256,24 +3256,44 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
32563256

32573257
// On SnowLeopard we should set "DYLD_NO_PIE" in the inferior environment....
32583258

3259-
#if !defined(__arm__)
3260-
3261-
// We don't need to do this for ARM, and we really shouldn't now that we
3262-
// have multiple CPU subtypes and no posix_spawnattr call that allows us
3263-
// to set which CPU subtype to launch...
32643259
if (cpu_type != 0) {
32653260
size_t ocount = 0;
3266-
err.SetError(::posix_spawnattr_setbinpref_np(&attr, 1, &cpu_type, &ocount),
3267-
DNBError::POSIX);
3268-
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
3269-
err.LogThreaded("::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = "
3270-
"0x%8.8x, count => %llu )",
3271-
cpu_type, (uint64_t)ocount);
3261+
bool slice_preference_set = false;
3262+
3263+
if (cpu_subtype != 0) {
3264+
typedef int (*posix_spawnattr_setarchpref_np_t)(
3265+
posix_spawnattr_t *, size_t, cpu_type_t *, cpu_subtype_t *, size_t *);
3266+
posix_spawnattr_setarchpref_np_t posix_spawnattr_setarchpref_np_fn =
3267+
(posix_spawnattr_setarchpref_np_t)dlsym(
3268+
RTLD_DEFAULT, "posix_spawnattr_setarchpref_np");
3269+
if (posix_spawnattr_setarchpref_np_fn) {
3270+
err.SetError((*posix_spawnattr_setarchpref_np_fn)(
3271+
&attr, 1, &cpu_type, &cpu_subtype, &ocount));
3272+
slice_preference_set = err.Success();
3273+
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
3274+
err.LogThreaded(
3275+
"::posix_spawnattr_setarchpref_np ( &attr, 1, cpu_type = "
3276+
"0x%8.8x, cpu_subtype = 0x%8.8x, count => %llu )",
3277+
cpu_type, cpu_subtype, (uint64_t)ocount);
3278+
if (err.Fail() != 0 || ocount != 1)
3279+
return INVALID_NUB_PROCESS;
3280+
}
3281+
}
32723282

3273-
if (err.Fail() != 0 || ocount != 1)
3274-
return INVALID_NUB_PROCESS;
3283+
if (!slice_preference_set) {
3284+
err.SetError(
3285+
::posix_spawnattr_setbinpref_np(&attr, 1, &cpu_type, &ocount),
3286+
DNBError::POSIX);
3287+
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
3288+
err.LogThreaded(
3289+
"::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = "
3290+
"0x%8.8x, count => %llu )",
3291+
cpu_type, (uint64_t)ocount);
3292+
3293+
if (err.Fail() != 0 || ocount != 1)
3294+
return INVALID_NUB_PROCESS;
3295+
}
32753296
}
3276-
#endif
32773297

32783298
PseudoTerminal pty;
32793299

Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
RUN: llvm-nm %p/Inputs/redacted-function.macho-aarch64 | FileCheck %s
2+
3+
CHECK: <redacted function 1>
4+
5+
# Generated with:
6+
# $ cat /tmp/a.c
7+
# static int i(void) {
8+
# return 0;
9+
# }
10+
#
11+
# int main(void) {
12+
# return i();
13+
# }
14+
#
15+
# $ xcrun -sdk watchos clang -arch arm64_32 /tmp/a.c -o /tmp/redacted-function.macho-aarch64
16+
# $ xcrun -sdk watchos strip -N /tmp/redacted-function.macho-aarch64

llvm/tools/llvm-nm/llvm-nm.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,20 @@ struct NMSymbol {
316316
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
317317
bool ADefined;
318318
// Symbol flags have been checked in the caller.
319-
uint32_t AFlags = cantFail(A.Sym.getFlags());
320-
if (A.Sym.getRawDataRefImpl().p)
319+
if (A.Sym.getRawDataRefImpl().p) {
320+
uint32_t AFlags = cantFail(A.Sym.getFlags());
321321
ADefined = !(AFlags & SymbolRef::SF_Undefined);
322-
else
322+
} else {
323323
ADefined = A.TypeChar != 'U';
324+
}
324325
bool BDefined;
325326
// Symbol flags have been checked in the caller.
326-
uint32_t BFlags = cantFail(B.Sym.getFlags());
327-
if (B.Sym.getRawDataRefImpl().p)
327+
if (B.Sym.getRawDataRefImpl().p) {
328+
uint32_t BFlags = cantFail(B.Sym.getFlags());
328329
BDefined = !(BFlags & SymbolRef::SF_Undefined);
329-
else
330+
} else {
330331
BDefined = B.TypeChar != 'U';
332+
}
331333
return std::make_tuple(ADefined, A.Address, A.Name, A.Size) <
332334
std::make_tuple(BDefined, B.Address, B.Name, B.Size);
333335
}

0 commit comments

Comments
 (0)