From 521f9e77e311980917646323c875f22f08d2cb9a Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Thu, 1 Dec 2022 17:28:56 +0000 Subject: [PATCH 1/4] [OHOS][lldb] Use LLDB_LOGF macro to avoid null-pointer dereference Change-Id: I4facdaa183890185be1552c15ed8194beaf5a681 Signed-off-by: Nikolai Kholiavin --- .../Interpreter/OptionGroupPlatform.cpp | 8 +- .../source/Plugins/Platform/HOS/HdcClient.cpp | 163 +++++++----------- .../Plugins/Platform/HOS/PlatformHOS.cpp | 79 ++++----- .../HOS/PlatformHOSRemoteGDBServer.cpp | 44 +++-- .../Plugins/Platform/OHOS/PlatformOHOS.cpp | 21 +-- .../OHOS/PlatformOHOSRemoteGDBServer.cpp | 43 ++--- 6 files changed, 148 insertions(+), 210 deletions(-) diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp index 45694fe112df..710f1c54df3c 100644 --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -22,9 +22,8 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions( PlatformSP platform_sp; Log *log = GetLog(LLDBLog::Commands); - if (log) - log->Printf("Hsu file(%s):%d OptionGroupPlatform::%s call make_selected:%d", - __FILE__, __LINE__, __FUNCTION__, make_selected); + LLDB_LOGF(log, "Hsu file(%s):%d OptionGroupPlatform::%s call make_selected:%d", + __FILE__, __LINE__, __FUNCTION__, make_selected); if (!m_platform_name.empty()) { platform_sp = platforms.Create(m_platform_name); if (!platform_sp) { @@ -34,8 +33,7 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions( } if (platform_sp) { if (GetContainer()) { - if (log) - log->Printf("Platform is created inside container."); + LLDB_LOGF(log, "Platform is created inside container."); platform_sp->SetContainer(true); } if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture( diff --git a/lldb/source/Plugins/Platform/HOS/HdcClient.cpp b/lldb/source/Plugins/Platform/HOS/HdcClient.cpp index 4ee3d17b73dc..c6fd01c8eab7 100644 --- a/lldb/source/Plugins/Platform/HOS/HdcClient.cpp +++ b/lldb/source/Plugins/Platform/HOS/HdcClient.cpp @@ -100,9 +100,8 @@ Status HdcClient::CreateByDeviceID(const std::string &device_id, if (error.Fail()) return error; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s device_id(%s)", __FILE__, - __LINE__, __FUNCTION__, device_id.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s device_id(%s)", __FILE__, + __LINE__, __FUNCTION__, device_id.c_str()); std::string android_serial; if (!device_id.empty()) android_serial = device_id; @@ -135,18 +134,16 @@ HdcClient::~HdcClient() {} void HdcClient::SetDeviceID(const std::string &device_id) { m_device_id = device_id; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s m_device_id(%s)", __FILE__, - __LINE__, __FUNCTION__, m_device_id.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s m_device_id(%s)", __FILE__, + __LINE__, __FUNCTION__, m_device_id.c_str()); } const std::string &HdcClient::GetDeviceID() const { return m_device_id; } Status HdcClient::Connect() { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s new ConnectionFileDescriptor", - __FILE__, __LINE__, __FUNCTION__); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s new ConnectionFileDescriptor", + __FILE__, __LINE__, __FUNCTION__); Status error; m_conn.reset(new ConnectionFileDescriptor); std::string port = "5037"; @@ -154,15 +151,13 @@ Status HdcClient::Connect() { const char *env_port = std::getenv("HDC_SERVER_PORT"); if ((env_port != NULL) && (atoi(env_port) > 0)) { port = env_port; - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s env_port(%s) port(%s)", - __FILE__, __LINE__, __FUNCTION__, env_port, port.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s env_port(%s) port(%s)", + __FILE__, __LINE__, __FUNCTION__, env_port, port.c_str()); } std::string uri = "connect://127.0.0.1:" + port; - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s uri(%s)", __FILE__, __LINE__, - __FUNCTION__, uri.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s uri(%s)", __FILE__, __LINE__, + __FUNCTION__, uri.c_str()); m_conn->Connect(uri.c_str(), &error); return error; @@ -171,9 +166,8 @@ Status HdcClient::Connect() { Status HdcClient::GetDevices(DeviceIDList &device_list) { device_list.clear(); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s call", __FILE__, __LINE__, - __FUNCTION__); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s call", __FILE__, __LINE__, + __FUNCTION__); auto error = SendMessage("host:devices"); if (error.Fail()) return error; @@ -201,16 +195,14 @@ Status HdcClient::GetDevices(DeviceIDList &device_list) { Status HdcClient::SetPortForwarding(const uint16_t local_port, const uint16_t remote_port) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s local_port(%d) remote_port(%d)", - __FILE__, __LINE__, __FUNCTION__, local_port, remote_port); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s local_port(%d) remote_port(%d)", + __FILE__, __LINE__, __FUNCTION__, local_port, remote_port); char message[48]; snprintf(message, sizeof(message), "forward:tcp:%d;tcp:%d", local_port, remote_port); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, - __FUNCTION__, message); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, + __FUNCTION__, message); const auto error = SendDeviceMessage(message); if (error.Fail()) return error; @@ -223,9 +215,8 @@ HdcClient::SetPortForwarding(const uint16_t local_port, llvm::StringRef remote_socket_name, const UnixSocketNamespace socket_namespace) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s local_port(%d)", __FILE__, - __LINE__, __FUNCTION__, local_port); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s local_port(%d)", __FILE__, + __LINE__, __FUNCTION__, local_port); char message[PATH_MAX]; const char *sock_namespace_str = (socket_namespace == UnixSocketNamespaceAbstract) @@ -234,9 +225,8 @@ HdcClient::SetPortForwarding(const uint16_t local_port, snprintf(message, sizeof(message), "forward:tcp:%d;%s:%s", local_port, sock_namespace_str, remote_socket_name.str().c_str()); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, - __FUNCTION__, message); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, + __FUNCTION__, message); const auto error = SendDeviceMessage(message); if (error.Fail()) return error; @@ -246,15 +236,13 @@ HdcClient::SetPortForwarding(const uint16_t local_port, Status HdcClient::DeletePortForwarding(const uint16_t local_port) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s local_port(%d)", __FILE__, - __LINE__, __FUNCTION__, local_port); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s local_port(%d)", __FILE__, + __LINE__, __FUNCTION__, local_port); char message[32]; snprintf(message, sizeof(message), "killforward:tcp:%d", local_port); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, - __FUNCTION__, message); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s message(%s)", __FILE__, __LINE__, + __FUNCTION__, message); const auto error = SendDeviceMessage(message); if (error.Fail()) return error; @@ -265,9 +253,8 @@ Status HdcClient::DeletePortForwarding(const uint16_t local_port) { Status HdcClient::SendMessage(const std::string &packet, const bool reconnect) { Status error; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s packet(%s) reconnect(%d)", - __FILE__, __LINE__, __FUNCTION__, packet.c_str(), reconnect); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s packet(%s) reconnect(%d)", + __FILE__, __LINE__, __FUNCTION__, packet.c_str(), reconnect); if (!m_conn || reconnect) { error = Connect(); if (error.Fail()) @@ -290,15 +277,13 @@ Status HdcClient::SendMessage(const std::string &packet, const bool reconnect) { Status HdcClient::SendDeviceMessage(const std::string &packet) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s packet(%s) ", __FILE__, __LINE__, - __FUNCTION__, packet.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s packet(%s) ", __FILE__, __LINE__, + __FUNCTION__, packet.c_str()); std::ostringstream msg; msg << "host-serial:" << m_device_id << ":" << packet; - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s msg(%s) ", __FILE__, __LINE__, - __FUNCTION__, msg.str().c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s msg(%s) ", __FILE__, __LINE__, + __FUNCTION__, msg.str().c_str()); return SendMessage(msg.str()); } @@ -306,9 +291,8 @@ Status HdcClient::SendDeviceMessage(const std::string &packet) { Status HdcClient::ReadMessage(std::vector &message) { message.clear(); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s call ", __FILE__, __LINE__, - __FUNCTION__); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s call ", __FILE__, __LINE__, + __FUNCTION__); char buffer[5]; buffer[4] = 0; @@ -332,9 +316,8 @@ Status HdcClient::ReadMessageStream(std::vector &message, auto start = steady_clock::now(); message.clear(); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s call ", __FILE__, __LINE__, - __FUNCTION__); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s call ", __FILE__, __LINE__, + __FUNCTION__); Status error; lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess; @@ -364,9 +347,8 @@ Status HdcClient::ReadResponseStatus() { return error; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s response_id(%s) ", __FILE__, - __LINE__, __FUNCTION__, response_id); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s response_id(%s) ", __FILE__, + __LINE__, __FUNCTION__, response_id); if (strncmp(response_id, kOKAY, packet_len) != 0) return GetResponseError(response_id); @@ -378,9 +360,8 @@ Status HdcClient::GetResponseError(const char *response_id) { if (strcmp(response_id, kFAIL) != 0) return Status("Got unexpected response id from hdc: \"%s\"", response_id); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s response_id(%s) ", __FILE__, - __LINE__, __FUNCTION__, response_id); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s response_id(%s) ", __FILE__, + __LINE__, __FUNCTION__, response_id); std::vector error_message; auto error = ReadMessage(error_message); @@ -399,10 +380,9 @@ Status HdcClient::SwitchDeviceTransport() { if (error.Fail()) return error; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s m_device_id(%s) msg(%s)", - __FILE__, __LINE__, __FUNCTION__, m_device_id.c_str(), - msg.str().c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s m_device_id(%s) msg(%s)", + __FILE__, __LINE__, __FUNCTION__, m_device_id.c_str(), + msg.str().c_str()); return ReadResponseStatus(); } @@ -471,9 +451,8 @@ Status HdcClient::Shell(const char *command, milliseconds timeout, std::string *output) { std::vector output_buffer; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s command(%s)", __FILE__, __LINE__, - __FUNCTION__, command); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s command(%s)", __FILE__, __LINE__, + __FUNCTION__, command); auto error = internalShell(command, timeout, output_buffer); if (error.Fail()) @@ -488,9 +467,8 @@ Status HdcClient::ShellToFile(const char *command, milliseconds timeout, const FileSpec &output_file_spec) { std::vector output_buffer; Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s command(%s)", __FILE__, __LINE__, - __FUNCTION__, command); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s command(%s)", __FILE__, __LINE__, + __FUNCTION__, command); auto error = internalShell(command, timeout, output_buffer); if (error.Fail()) @@ -499,9 +477,8 @@ Status HdcClient::ShellToFile(const char *command, milliseconds timeout, const auto output_filename = output_file_spec.GetPath(); std::error_code EC; llvm::raw_fd_ostream dst(output_filename, EC, llvm::sys::fs::OF_None); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s output_filename(%s)", __FILE__, - __LINE__, __FUNCTION__, output_filename.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s output_filename(%s)", __FILE__, + __LINE__, __FUNCTION__, output_filename.c_str()); if (EC) return Status("Unable to open local file %s", output_filename.c_str()); @@ -530,9 +507,8 @@ Status HdcClient::SyncService::internalPullFile(const FileSpec &remote_file, std::error_code EC; llvm::raw_fd_ostream dst(local_file_path, EC, llvm::sys::fs::OF_None); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s local_file_path(%s)", __FILE__, - __LINE__, __FUNCTION__, local_file_path.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s local_file_path(%s)", __FILE__, + __LINE__, __FUNCTION__, local_file_path.c_str()); if (EC) return Status("Unable to open local file %s", local_file_path.c_str()); @@ -540,9 +516,8 @@ Status HdcClient::SyncService::internalPullFile(const FileSpec &remote_file, const auto remote_file_path = remote_file.GetPath(false); auto error = SendSyncRequest(kRECV, remote_file_path.length(), remote_file_path.c_str()); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s remote_file_path(%s)", __FILE__, - __LINE__, __FUNCTION__, remote_file_path.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s remote_file_path(%s)", __FILE__, + __LINE__, __FUNCTION__, remote_file_path.c_str()); if (error.Fail()) return error; @@ -569,9 +544,8 @@ Status HdcClient::SyncService::internalPushFile(const FileSpec &local_file, const auto local_file_path(local_file.GetPath()); std::ifstream src(local_file_path.c_str(), std::ios::in | std::ios::binary); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s local_file_path(%s)", __FILE__, - __LINE__, __FUNCTION__, local_file_path.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s local_file_path(%s)", __FILE__, + __LINE__, __FUNCTION__, local_file_path.c_str()); if (!src.is_open()) return Status("Unable to open local file %s", local_file_path.c_str()); @@ -581,9 +555,8 @@ Status HdcClient::SyncService::internalPushFile(const FileSpec &local_file, std::string file_description_str = file_description.str(); auto error = SendSyncRequest(kSEND, file_description_str.length(), file_description_str.c_str()); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s file_description_str(%s)", - __FILE__, __LINE__, __FUNCTION__, file_description_str.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s file_description_str(%s)", + __FILE__, __LINE__, __FUNCTION__, file_description_str.c_str()); if (error.Fail()) return error; @@ -631,9 +604,8 @@ Status HdcClient::SyncService::internalStat(const FileSpec &remote_file, auto error = SendSyncRequest(kSTAT, remote_file_path.length(), remote_file_path.c_str()); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s remote_file_path(%s)", __FILE__, - __LINE__, __FUNCTION__, remote_file_path.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s remote_file_path(%s)", __FILE__, + __LINE__, __FUNCTION__, remote_file_path.c_str()); if (error.Fail()) return Status("Failed to send request: %s", error.AsCString()); @@ -666,10 +638,9 @@ Status HdcClient::SyncService::internalStat(const FileSpec &remote_file, Status HdcClient::SyncService::PullFile(const FileSpec &remote_file, const FileSpec &local_file) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s remote_file(%s) local_file(%s)", - __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), - local_file.GetPath().c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s remote_file(%s) local_file(%s)", + __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), + local_file.GetPath().c_str()); return executeCommand([this, &remote_file, &local_file]() { return internalPullFile(remote_file, local_file); @@ -679,10 +650,9 @@ Status HdcClient::SyncService::PullFile(const FileSpec &remote_file, Status HdcClient::SyncService::PushFile(const FileSpec &local_file, const FileSpec &remote_file) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s remote_file(%s) local_file(%s)", - __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), - local_file.GetPath().c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s remote_file(%s) local_file(%s)", + __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), + local_file.GetPath().c_str()); return executeCommand([this, &local_file, &remote_file]() { return internalPushFile(local_file, remote_file); }); @@ -691,10 +661,9 @@ Status HdcClient::SyncService::PushFile(const FileSpec &local_file, Status HdcClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size, uint32_t &mtime) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d HdcClient::%s remote_file(%s) mode(%d)", - __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), - mode); + LLDB_LOGF(log, "Hsu file(%s):%d HdcClient::%s remote_file(%s) mode(%d)", + __FILE__, __LINE__, __FUNCTION__, remote_file.GetPath().c_str(), + mode); return executeCommand([this, &remote_file, &mode, &size, &mtime]() { return internalStat(remote_file, mode, size, mtime); }); diff --git a/lldb/source/Plugins/Platform/HOS/PlatformHOS.cpp b/lldb/source/Plugins/Platform/HOS/PlatformHOS.cpp index 808d2af4a0b7..83e6453834f9 100644 --- a/lldb/source/Plugins/Platform/HOS/PlatformHOS.cpp +++ b/lldb/source/Plugins/Platform/HOS/PlatformHOS.cpp @@ -51,9 +51,8 @@ void PlatformHOS::Initialize() { PlatformSP default_platform_sp(new PlatformHOS(true)); default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture()); Platform::SetHostPlatform(default_platform_sp); - if (log) - log->Printf("Hsu file(%s)%d PlatformHOS::%s new PlatformHOS(true)", - __FILE__, __LINE__, __FUNCTION__); + LLDB_LOGF(log, "Hsu file(%s)%d PlatformHOS::%s new PlatformHOS(true)", + __FILE__, __LINE__, __FUNCTION__); #endif PluginManager::RegisterPlugin( PlatformHOS::GetPluginNameStatic(false), @@ -77,8 +76,8 @@ PlatformSP PlatformHOS::CreateInstance(bool force, const ArchSpec *arch) { const char *triple_cstr = arch ? arch->GetTriple().getTriple().c_str() : ""; - log->Printf("PlatformHOS::%s(force=%s, triple=%s)", __FUNCTION__, - force ? "true" : "false", triple_cstr); + LLDB_LOGF(log, "PlatformHOS::%s(force=%s, triple=%s)", __FUNCTION__, + force ? "true" : "false", triple_cstr); } bool create = force; @@ -100,12 +99,11 @@ PlatformSP PlatformHOS::CreateInstance(bool force, const ArchSpec *arch) { if (const char *env = std::getenv("HDC_UTID")) platform_setenv("ANDROID_SERIAL", env); - log->Printf("PlatformHOS::%s() creating remote-hos platform", __FUNCTION__); + LLDB_LOGF(log, "PlatformHOS::%s() creating remote-hos platform", __FUNCTION__); return PlatformSP(new PlatformHOS(false)); } - log->Printf("PlatformHOS::%s() aborting creation of remote-hos platform", - __FUNCTION__); + LLDB_LOGF(log, "PlatformHOS::%s() aborting creation of remote-hos platform", __FUNCTION__); return PlatformSP(); } @@ -113,27 +111,23 @@ PlatformSP PlatformHOS::CreateInstance(bool force, const ArchSpec *arch) { PlatformHOS::PlatformHOS(bool is_host) : PlatformLinux(is_host), m_sdk_version(0) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d PlatformHOS::%s is_host(%d)", __FILE__, - __LINE__, __FUNCTION__, is_host); + LLDB_LOGF(log, "Hsu file(%s):%d PlatformHOS::%s is_host(%d)", __FILE__, + __LINE__, __FUNCTION__, is_host); } PlatformHOS::~PlatformHOS() {} llvm::StringRef PlatformHOS::GetPluginNameStatic(bool is_host) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu %s:%d PlatformHOS::GetPluginNameStatic is_host(%d)", - __FILE__, __LINE__, is_host); + LLDB_LOGF(log, "Hsu %s:%d PlatformHOS::GetPluginNameStatic is_host(%d)", + __FILE__, __LINE__, is_host); if (is_host) { - if (log) - log->Printf("Hsu %s:%d PlatformHOS::GetPluginNameStatic g_host_name", - __FILE__, __LINE__); + LLDB_LOGF(log, "Hsu %s:%d PlatformHOS::GetPluginNameStatic g_host_name", + __FILE__, __LINE__); return Platform::GetHostPlatformName(); } else { - if (log) - log->Printf("Hsu %s:%d PlatformHOS::GetPluginNameStatic g_remote_name", - __FILE__, __LINE__); + LLDB_LOGF(log, "Hsu %s:%d PlatformHOS::GetPluginNameStatic g_remote_name", + __FILE__, __LINE__); return "remote-hos"; } } @@ -148,9 +142,8 @@ const char *PlatformHOS::GetPluginDescriptionStatic(bool is_host) { Status PlatformHOS::ConnectRemote(Args &args) { m_device_id.clear(); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu %s:%d PlatformHOS::ConnectRemote call", __FILE__, - __LINE__); + LLDB_LOGF(log, "Hsu %s:%d PlatformHOS::ConnectRemote call", __FILE__, + __LINE__); if (IsHost()) { return Status("can't connect to the host platform '%s', always connected", @@ -158,10 +151,8 @@ Status PlatformHOS::ConnectRemote(Args &args) { } if (!m_remote_platform_sp) { - if (log) - log->Printf("Hsu %s:%d PlatformHOS::ConnectRemote new " - "PlatformHOSRemoteGDBServer()", - __FILE__, __LINE__); + LLDB_LOGF(log, "Hsu %s:%d PlatformHOS::ConnectRemote new " + "PlatformHOSRemoteGDBServer()", __FILE__, __LINE__); m_remote_platform_sp = PlatformSP(new PlatformHOSRemoteGDBServer()); } @@ -177,17 +168,15 @@ Status PlatformHOS::ConnectRemote(Args &args) { auto error = PlatformLinux::ConnectRemote(args); if (error.Success()) { HdcClient hdc; - if (log) - log->Printf("Hsu file(%s):%d PlatformHOS::ConnectRemote m_device_id(%s)", - __FILE__, __LINE__, m_device_id.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d PlatformHOS::ConnectRemote m_device_id(%s)", + __FILE__, __LINE__, m_device_id.c_str()); error = HdcClient::CreateByDeviceID(m_device_id, hdc); if (error.Fail()) return error; m_device_id = hdc.GetDeviceID(); - if (log) - log->Printf("Hsu file(%s):%d PlatformHOS::ConnectRemote m_device_id(%s)", - __FILE__, __LINE__, m_device_id.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d PlatformHOS::ConnectRemote m_device_id(%s)", + __FILE__, __LINE__, m_device_id.c_str()); } return error; } @@ -218,18 +207,16 @@ Status PlatformHOS::GetFile(const FileSpec &source, auto source_file = source_spec.GetCString(false); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Got mode == 0 on '%s': try to get file via 'shell cat'", - source_file); + LLDB_LOGF(log, "Got mode == 0 on '%s': try to get file via 'shell cat'", + source_file); if (strchr(source_file, '\'') != nullptr) return Status("Doesn't support single-quotes in filenames"); // mode == 0 can signify that adbd cannot access the file due security // constraints - try "cat ..." as a fallback. - if (log) - log->Printf("Hsu file(%s):%d PlatformHOS::%s source_file(%s)", __FILE__, - __LINE__, __FUNCTION__, source_file); + LLDB_LOGF(log, "Hsu file(%s):%d PlatformHOS::%s source_file(%s)", __FILE__, + __LINE__, __FUNCTION__, source_file); HdcClient hdc(m_device_id); char cmd[PATH_MAX]; @@ -270,9 +257,8 @@ Status PlatformHOS::GetFile(const FileSpec &source, snprintf(cmd, sizeof(cmd), "cat '%s'", source_file); } - if (log) - log->Printf("Hsu file(%s):%d PlatformHOS::%s source_file(%s)", __FILE__, - __LINE__, __FUNCTION__, source_file); + LLDB_LOGF(log, "Hsu file(%s):%d PlatformHOS::%s source_file(%s)", __FILE__, + __LINE__, __FUNCTION__, source_file); return hdc.ShellToFile(cmd, minutes(1), destination); } @@ -335,9 +321,8 @@ uint32_t PlatformHOS::GetSdkVersion() { if (error.Fail() || version_string.empty()) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Get SDK version failed. (error: %s, output: %s)", - error.AsCString(), version_string.c_str()); + LLDB_LOGF(log, "Get SDK version failed. (error: %s, output: %s)", + error.AsCString(), version_string.c_str()); return 0; } @@ -389,8 +374,8 @@ Status PlatformHOS::DownloadSymbolFile(const lldb::ModuleSP &module_sp, Status error = hdc.Shell(command.GetData(), seconds(5), nullptr); Log *log = GetLog(LLDBLog::Platform); - if (log && error.Fail()) - log->Printf("Failed to remove temp directory: %s", error.AsCString()); + if (error.Fail()) + LLDB_LOGF(log, "Failed to remove temp directory: %s", error.AsCString()); }); FileSpec symfile_platform_filespec(tmpdir); diff --git a/lldb/source/Plugins/Platform/HOS/PlatformHOSRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/HOS/PlatformHOSRemoteGDBServer.cpp index 344300ea0086..13ae858211ef 100644 --- a/lldb/source/Plugins/Platform/HOS/PlatformHOSRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/HOS/PlatformHOSRemoteGDBServer.cpp @@ -36,20 +36,20 @@ static Status ForwardPortWithHdc( return error; device_id = hdc.GetDeviceID(); - log->Printf("Hsu file(%s):%d function(ForwardPortWithHdc) Connected to Hos " - "device \"%s\"", - __FILE__, __LINE__, device_id.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d function(ForwardPortWithHdc) Connected to Hos " + "device \"%s\"", + __FILE__, __LINE__, device_id.c_str()); if (remote_port != 0) { - log->Printf( - "Hsu file(%s):%d function(ForwardPortWithHdc) Forwarding remote " - "TCP port %d to local TCP port %d", - __FILE__, __LINE__, remote_port, local_port); + LLDB_LOGF(log, + "Hsu file(%s):%d function(ForwardPortWithHdc) Forwarding remote " + "TCP port %d to local TCP port %d", + __FILE__, __LINE__, remote_port, local_port); return hdc.SetPortForwarding(local_port, remote_port); } - log->Printf("Forwarding remote socket \"%s\" to local TCP port %d", - remote_socket_name.str().c_str(), local_port); + LLDB_LOGF(log, "Forwarding remote socket \"%s\" to local TCP port %d", + remote_socket_name.str().c_str(), local_port); if (!socket_namespace) return Status("Invalid socket namespace"); @@ -75,9 +75,8 @@ static Status FindUnusedPort(uint16_t &port) { port = tcp_socket->GetLocalPortNumber(); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d FindUnusedPort port(%d)", __FILE__, __LINE__, - port); + LLDB_LOGF(log, "Hsu file(%s):%d FindUnusedPort port(%d)", __FILE__, __LINE__, + port); return error; } @@ -99,8 +98,8 @@ bool PlatformHOSRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid, Log *log = GetLog(LLDBLog::Platform); auto error = MakeConnectURL(pid, remote_port, socket_name.c_str(), connect_url); - if (error.Success() && log) - log->Printf("gdbserver connect URL: %s", connect_url.c_str()); + if (error.Success()) + LLDB_LOGF(log, "gdbserver connect URL: %s", connect_url.c_str()); return error.Success(); } @@ -139,17 +138,16 @@ Status PlatformHOSRemoteGDBServer::ConnectRemote(Args &args) { auto error = MakeConnectURL(g_remote_platform_pid, remote_port, uri->path, connect_url); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Hsu file(%s):%d g_remote_platform_pid(%lu) remote_port(%d) " - "connect_url(%s)", - __FILE__, __LINE__, g_remote_platform_pid, remote_port, - connect_url.c_str()); + LLDB_LOGF(log, "Hsu file(%s):%d g_remote_platform_pid(%lu) remote_port(%d) " + "connect_url(%s)", + __FILE__, __LINE__, g_remote_platform_pid, remote_port, + connect_url.c_str()); if (error.Fail()) return error; args.ReplaceArgumentAtIndex(0, connect_url); - log->Printf("Rewritten platform connect URL: %s", connect_url.c_str()); + LLDB_LOGF(log, "Rewritten platform connect URL: %s", connect_url.c_str()); error = PlatformRemoteGDBServer::ConnectRemote(args); if (error.Fail()) @@ -172,9 +170,9 @@ void PlatformHOSRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) { const auto port = it->second; const auto error = DeleteForwardPortWithHdc(port, m_device_id); if (error.Fail()) - log->Printf("Failed to delete port forwarding (pid=%" PRIu64 - ", port=%d, device=%s): %s", - pid, port, m_device_id.c_str(), error.AsCString()); + LLDB_LOGF(log, "Failed to delete port forwarding (pid=%" PRIu64 + ", port=%d, device=%s): %s", + pid, port, m_device_id.c_str(), error.AsCString()); m_port_forwards.erase(it); } diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index eb0cfd9c7fff..ecc7ba66b2f0 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -71,8 +71,8 @@ PlatformSP PlatformOHOS::CreateInstance(bool force, const ArchSpec *arch) { const char *triple_cstr = arch ? arch->GetTriple().getTriple().c_str() : ""; - log->Printf("PlatformOHOS::%s(force=%s, arch={%s,%s})", __FUNCTION__, - force ? "true" : "false", arch_name, triple_cstr); + LLDB_LOGF(log, "PlatformOHOS::%s(force=%s, arch={%s,%s})", __FUNCTION__, + force ? "true" : "false", arch_name, triple_cstr); } bool create = force; @@ -98,17 +98,15 @@ PlatformSP PlatformOHOS::CreateInstance(bool force, const ArchSpec *arch) { } if (create) { - if (log) - log->Printf("PlatformOHOS::%s() creating remote-ohos platform", - __FUNCTION__); + LLDB_LOGF(log, "PlatformOHOS::%s() creating remote-ohos platform", + __FUNCTION__); return PlatformSP(new PlatformOHOS(false)); } - if (log) - log->Printf( - "PlatformOHOS::%s() aborting creation of remote-ohos platform", - __FUNCTION__); + LLDB_LOGF(log, + "PlatformOHOS::%s() aborting creation of remote-ohos platform", + __FUNCTION__); return PlatformSP(); } @@ -236,9 +234,8 @@ uint32_t PlatformOHOS::GetSdkVersion() { if (error.Fail() || version_string.empty()) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Get SDK version failed. (error: %s, output: %s)", - error.AsCString(), version_string.c_str()); + LLDB_LOGF(log, "Get SDK version failed. (error: %s, output: %s)", + error.AsCString(), version_string.c_str()); m_sdk_version = INVALID_SDK_VERSION; return 0; } diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp index 348572ec0553..28f996a6cdb7 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOSRemoteGDBServer.cpp @@ -38,19 +38,16 @@ static Status ForwardPortWithHdc( return error; device_id = hdc.GetDeviceID(); - if (log) - log->Printf("Connected to OHOS device \"%s\"", device_id.c_str()); + LLDB_LOGF(log, "Connected to OHOS device \"%s\"", device_id.c_str()); if (remote_port != 0) { - if (log) - log->Printf("Forwarding remote TCP port %d to local TCP port %d", - remote_port, local_port); + LLDB_LOGF(log, "Forwarding remote TCP port %d to local TCP port %d", + remote_port, local_port); return hdc.SetPortForwarding(local_port, remote_port); } - if (log) - log->Printf("Forwarding remote socket \"%s\" to local TCP port %d", - remote_socket_name.str().c_str(), local_port); + LLDB_LOGF(log, "Forwarding remote socket \"%s\" to local TCP port %d", + remote_socket_name.str().c_str(), local_port); if (!socket_namespace) return Status("Invalid socket namespace"); @@ -62,9 +59,8 @@ static Status ForwardPortWithHdc( static Status DeleteForwardPortWithHdc(std::pair ports, const std::string &device_id) { Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Delete port forwarding %d -> %d, device=%s", ports.first, - ports.second, device_id.c_str()); + LLDB_LOGF(log, "Delete port forwarding %d -> %d, device=%s", ports.first, + ports.second, device_id.c_str()); HdcClient hdc(device_id); return hdc.DeletePortForwarding(ports); @@ -77,8 +73,7 @@ static Status DeleteForwardPortWithHdc(std::pair remote_s Log *log = GetLog(LLDBLog::Platform); uint16_t local_port = remote_socket.first; std::string remote_socket_name = remote_socket.second; - if (log) - log->Printf("Delete port forwarding %d -> %s, device=%s", local_port, + LLDB_LOGF(log, "Delete port forwarding %d -> %s, device=%s", local_port, remote_socket_name.c_str(), device_id.c_str()); if (!socket_namespace) return Status("Invalid socket namespace"); @@ -129,8 +124,8 @@ bool PlatformOHOSRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid, auto error = MakeConnectURL(pid, remote_port, socket_name.c_str(), connect_url); - if (error.Success() && log) - log->Printf("gdbserver connect URL: %s", connect_url.c_str()); + if (error.Success()) + LLDB_LOGF(log, "gdbserver connect URL: %s", connect_url.c_str()); return error.Success(); } @@ -174,9 +169,7 @@ Status PlatformOHOSRemoteGDBServer::ConnectRemote(Args &args) { args.ReplaceArgumentAtIndex(0, connect_url); Log *log = GetLog(LLDBLog::Platform); - if (log) - log->Printf("Rewritten platform connect URL: %s", connect_url.c_str()); - + LLDB_LOGF(log, "Rewritten platform connect URL: %s", connect_url.c_str()); error = PlatformRemoteGDBServer::ConnectRemote(args); if (error.Fail()) DeleteForwardPort(g_remote_platform_pid); @@ -198,11 +191,10 @@ void PlatformOHOSRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) { if (it != m_port_forwards.end() && it->second.second != 0) { const auto error = DeleteForwardPortWithHdc(it->second, m_device_id); if (error.Fail()) { - if (log) - log->Printf("Failed to delete port forwarding (pid=%" PRIu64 - ", fwd=(%d -> %d), device=%s): %s", - pid, it->second.first, it->second.second, m_device_id.c_str(), - error.AsCString()); + LLDB_LOGF(log, "Failed to delete port forwarding (pid=%" PRIu64 + ", fwd=(%d -> %d), device=%s): %s", + pid, it->second.first, it->second.second, m_device_id.c_str(), + error.AsCString()); } m_port_forwards.erase(it); } @@ -210,9 +202,8 @@ void PlatformOHOSRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) { if(it_socket != m_remote_socket_name.end()) { const auto error_Socket = DeleteForwardPortWithHdc(it_socket->second, m_socket_namespace, m_device_id); if (error_Socket.Fail()) { - if (log) - log->Printf("Failed to delete port forwarding (pid=%" PRIu64 - ", fwd=(%d->%s)device=%s): %s", pid, it_socket->second.first, it_socket->second.second.c_str(), m_device_id.c_str(),error_Socket.AsCString()); + LLDB_LOGF(log, "Failed to delete port forwarding (pid=%" PRIu64 + ", fwd=(%d->%s)device=%s): %s", pid, it_socket->second.first, it_socket->second.second.c_str(), m_device_id.c_str(),error_Socket.AsCString()); } m_remote_socket_name.erase(it_socket); } -- Gitee From 5276ed161574cc7cb5e22fb56d94268090574af7 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Tue, 29 Nov 2022 20:30:47 +0000 Subject: [PATCH 2/4] [OHOS][lldb] Zero out option group platform to avoid uninitialized memory access Change-Id: I87d8567fd1ddf49794d4a406f1eac33120c510cf Signed-off-by: Nikolai Kholiavin --- lldb/include/lldb/Interpreter/OptionGroupPlatform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h index 3c24d77cdbe5..fda551a87e22 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupPlatform.h +++ b/lldb/include/lldb/Interpreter/OptionGroupPlatform.h @@ -67,7 +67,7 @@ protected: std::string m_platform_name; ConstString m_sdk_sysroot; ConstString m_sdk_build; - bool m_container; + bool m_container{}; llvm::VersionTuple m_os_version; bool m_include_platform_option; }; -- Gitee From a7ca58d30826012c21a087eb239f50e0049d32b3 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Thu, 1 Dec 2022 20:47:33 +0000 Subject: [PATCH 3/4] [test] Refactor ELF program-headers test to add new program header When adding a new program header to the test, all the offsets specified here are getting shifted by the program header size. Instead of patching every occurrence of the offset, use a numeric variable and pass its value to filecheck in a small number of places instead. Change-Id: I2c0246d5bbe757f2bedc07f1eaeaef67d076f635 Signed-off-by: Nikolai Kholiavin --- .../llvm-readobj/ELF/program-headers.test | 211 +++++++----------- 1 file changed, 86 insertions(+), 125 deletions(-) diff --git a/llvm/test/tools/llvm-readobj/ELF/program-headers.test b/llvm/test/tools/llvm-readobj/ELF/program-headers.test index e1cf4f9fb5f5..0f98d26e3ee9 100644 --- a/llvm/test/tools/llvm-readobj/ELF/program-headers.test +++ b/llvm/test/tools/llvm-readobj/ELF/program-headers.test @@ -19,74 +19,76 @@ # RUN: cmp %t.readobj-l.txt %t.readobj-segments.txt ## Check we are able to print program headers of different types. -# RUN: FileCheck %s --check-prefixes=ELF32,MAPPING \ +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x314 --check-prefixes=ELF32,MAPPING \ # RUN: --match-full-lines --strict-whitespace --input-file=%t.readelf-l.txt -# RUN: FileCheck %s --check-prefixes=ELF-LLVM,ELF32-LLVM \ +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x314 --check-prefixes=ELF-LLVM \ # RUN: --match-full-lines --input-file=%t.readobj-l.txt # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf # RUN: llvm-readelf -l %t64.elf | \ -# RUN: FileCheck %s --check-prefixes=ELF64,MAPPING --strict-whitespace --match-full-lines -# RUN: llvm-readobj -l %t64.elf | FileCheck %s --check-prefixes=ELF-LLVM,ELF64-LLVM +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefixes=ELF64,MAPPING \ +# RUN: --strict-whitespace --match-full-lines +# RUN: llvm-readobj -l %t64.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 \ +# RUN: --check-prefixes=ELF-LLVM # ELF32:There are 23 program headers, starting at offset 52 # ELF32-EMPTY: # ELF32-NEXT:Program Headers: # ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align -# ELF32-NEXT: PHDR 0x000314 0x00001000 0x00001000 0x00003 0x00003 W 0x1 -# ELF32-NEXT: PHDR 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 -# ELF32-NEXT: NULL 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 -# ELF32-NEXT: DYNAMIC 0x000314 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1 -# ELF32-NEXT: INTERP 0x00031e 0x00003000 0x00003000 0x00004 0x00004 RW 0x1 +# ELF32-NEXT: PHDR [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 W 0x1 +# ELF32-NEXT: PHDR [[#%#.6x,FOO_BEGIN+0x3]] 0x00002000 0x00002000 0x00007 0x00007 E 0x1 +# ELF32-NEXT: NULL [[#%#.6x,FOO_BEGIN+0x3]] 0x00002000 0x00002000 0x00007 0x00007 E 0x1 +# ELF32-NEXT: DYNAMIC [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1 +# ELF32-NEXT: INTERP [[#%#.6x,FOO_BEGIN+0xA]] 0x00003000 0x00003000 0x00004 0x00004 RW 0x1 # ELF32-NEXT: [Requesting program interpreter: ABC] -# ELF32-NEXT: NOTE 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: SHLIB 0x000314 0x00001000 0x00001000 0x00001 0x00001 0x1 -# ELF32-NEXT: TLS 0x000322 0x00004000 0x00004000 0x00001 0x00001 0x1 -# ELF32-NEXT: : 0x60000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: GNU_EH_FRAME 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: SUNW_UNWIND 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: GNU_STACK 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: GNU_RELRO 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: GNU_PROPERTY 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: OPENBSD_RANDOMIZE 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: OPENBSD_WXNEEDED 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: OPENBSD_BOOTDATA 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x6fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x70000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x70000001 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x70000002 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x70000003 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 -# ELF32-NEXT: : 0x7fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: NOTE [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: SHLIB [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00001 0x00001 0x1 +# ELF32-NEXT: TLS [[#%#.6x,FOO_BEGIN+0xE]] 0x00004000 0x00004000 0x00001 0x00001 0x1 +# ELF32-NEXT: : 0x60000000 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_EH_FRAME [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: SUNW_UNWIND [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_STACK [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_RELRO [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_PROPERTY [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: OPENBSD_RANDOMIZE [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: OPENBSD_WXNEEDED [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: OPENBSD_BOOTDATA [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x6fffffff [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000000 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000001 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000002 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000003 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x7fffffff [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 # ELF32-EMPTY: # ELF64:There are 23 program headers, starting at offset 64 # ELF64-EMPTY: # ELF64-NEXT:Program Headers: # ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align -# ELF64-NEXT: PHDR 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1 -# ELF64-NEXT: PHDR 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 -# ELF64-NEXT: NULL 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 -# ELF64-NEXT: DYNAMIC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1 -# ELF64-NEXT: INTERP 0x000552 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1 +# ELF64-NEXT: PHDR [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1 +# ELF64-NEXT: PHDR [[#%#.6x,FOO_BEGIN+0x3]] 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 +# ELF64-NEXT: NULL [[#%#.6x,FOO_BEGIN+0x3]] 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 +# ELF64-NEXT: DYNAMIC [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1 +# ELF64-NEXT: INTERP [[#%#.6x,FOO_BEGIN+0xA]] 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1 # ELF64-NEXT: [Requesting program interpreter: ABC] -# ELF64-NEXT: NOTE 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: SHLIB 0x000548 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1 -# ELF64-NEXT: TLS 0x000556 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1 -# ELF64-NEXT: : 0x60000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: GNU_EH_FRAME 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: SUNW_UNWIND 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: GNU_STACK 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: GNU_RELRO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: GNU_PROPERTY 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: OPENBSD_RANDOMIZE 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: OPENBSD_WXNEEDED 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: OPENBSD_BOOTDATA 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x6fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x70000001 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x70000003 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ELF64-NEXT: : 0x7fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: NOTE [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: SHLIB [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1 +# ELF64-NEXT: TLS [[#%#.6x,FOO_BEGIN+0xE]] 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1 +# ELF64-NEXT: : 0x60000000 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_EH_FRAME [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: SUNW_UNWIND [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_STACK [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_RELRO [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_PROPERTY [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: OPENBSD_RANDOMIZE [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: OPENBSD_WXNEEDED [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: OPENBSD_BOOTDATA [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x6fffffff [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000000 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000001 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000002 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000003 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x7fffffff [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # ELF64-EMPTY: # MAPPING: Section to Segment mapping: @@ -114,14 +116,12 @@ # MAPPING-NEXT: 20 .foo.begin .foo.end {{$}} # MAPPING-NEXT: 21 .foo.begin .foo.end {{$}} # MAPPING-NEXT: 22 .foo.begin .foo.end {{$}} -# MAPPING-NEXT: 23 .foo.begin .foo.end {{$}} # MAPPING-NEXT: None .unused .strtab .shstrtab {{$}} # ELF-LLVM: ProgramHeaders [ # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_PHDR (0x6) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -133,8 +133,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_PHDR (0x6) -# ELF32-LLVM-NEXT: Offset: 0x317 -# ELF64-LLVM-NEXT: Offset: 0x54B +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN+0x3]] # ELF-LLVM-NEXT: VirtualAddress: 0x2000 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000 # ELF-LLVM-NEXT: FileSize: 7 @@ -146,8 +145,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_NULL (0x0) -# ELF32-LLVM-NEXT: Offset: 0x317 -# ELF64-LLVM-NEXT: Offset: 0x54B +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN+0x3]] # ELF-LLVM-NEXT: VirtualAddress: 0x2000 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000 # ELF-LLVM-NEXT: FileSize: 7 @@ -159,8 +157,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_DYNAMIC (0x2) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -174,8 +171,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_INTERP (0x3) -# ELF32-LLVM-NEXT: Offset: 0x31E -# ELF64-LLVM-NEXT: Offset: 0x552 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN+0xA]] # ELF-LLVM-NEXT: VirtualAddress: 0x3000 # ELF-LLVM-NEXT: PhysicalAddress: 0x3000 # ELF-LLVM-NEXT: FileSize: 4 @@ -188,8 +184,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_NOTE (0x4) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -200,8 +195,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_SHLIB (0x5) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 1 @@ -212,8 +206,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_TLS (0x7) -# ELF32-LLVM-NEXT: Offset: 0x322 -# ELF64-LLVM-NEXT: Offset: 0x556 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN+0xE]] # ELF-LLVM-NEXT: VirtualAddress: 0x4000 # ELF-LLVM-NEXT: PhysicalAddress: 0x4000 # ELF-LLVM-NEXT: FileSize: 1 @@ -224,8 +217,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x60000000) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -236,8 +228,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -248,8 +239,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_SUNW_UNWIND (0x6464E550) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -260,8 +250,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_GNU_STACK (0x6474E551) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -272,8 +261,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_GNU_RELRO (0x6474E552) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -284,8 +272,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_GNU_PROPERTY (0x6474E553) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -296,8 +283,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_OPENBSD_RANDOMIZE (0x65A3DBE6) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -308,8 +294,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -320,8 +305,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: PT_OPENBSD_BOOTDATA (0x65A41BE6) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -332,8 +316,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x6FFFFFFF) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -344,8 +327,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x70000000) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -356,8 +338,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x70000001) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -368,8 +349,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x70000002) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -380,8 +360,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x70000003) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -392,20 +371,7 @@ # ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ProgramHeader { # ELF-LLVM-NEXT: Type: Unknown (0x7FFFFFFF) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 -# ELF-LLVM-NEXT: VirtualAddress: 0x1000 -# ELF-LLVM-NEXT: PhysicalAddress: 0x1000 -# ELF-LLVM-NEXT: FileSize: 3 -# ELF-LLVM-NEXT: MemSize: 3 -# ELF-LLVM-NEXT: Flags [ (0x0) -# ELF-LLVM-NEXT: ] -# ELF-LLVM-NEXT: Alignment: 1 -# ELF-LLVM-NEXT: } -# ELF-LLVM-NEXT: ProgramHeader { -# ELF-LLVM-NEXT: Type: PT_OHOS_RANDOMDATA (0x6788FC60) -# ELF32-LLVM-NEXT: Offset: 0x314 -# ELF64-LLVM-NEXT: Offset: 0x548 +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] # ELF-LLVM-NEXT: VirtualAddress: 0x1000 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000 # ELF-LLVM-NEXT: FileSize: 3 @@ -577,20 +543,15 @@ ProgramHeaders: VAddr: 0x1000 FirstSec: .foo.begin LastSec: .foo.end -## Case 23: the PT_OHOS_RANDOMDATA segment. - - Type: 0x6788FC60 ## PT_OHOS_RANDOMDATA - VAddr: 0x1000 - FirstSec: .foo.begin - LastSec: .foo.end ## Check how we dump ARM specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf -# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-GNU +# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=ARM-GNU # RUN: llvm-readobj --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-LLVM -# ARM-GNU: : 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ARM-GNU-NEXT: EXIDX 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# ARM-GNU-NEXT: : 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ARM-GNU: : 0x70000000 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ARM-GNU-NEXT: EXIDX [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ARM-GNU-NEXT: : 0x70000002 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # ARM-LLVM: ProgramHeader { # ARM-LLVM: Type: Unknown (0x70000000) @@ -601,13 +562,13 @@ ProgramHeaders: ## Check how we dump MIPS specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf -# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-GNU +# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=MIPS-GNU # RUN: llvm-readobj --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-LLVM -# MIPS-GNU: REGINFO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# MIPS-GNU-NEXT: RTPROC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# MIPS-GNU-NEXT: OPTIONS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -# MIPS-GNU-NEXT: ABIFLAGS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-GNU: REGINFO [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-GNU-NEXT: RTPROC [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-GNU-NEXT: OPTIONS [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-GNU-NEXT: ABIFLAGS [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # MIPS-LLVM: ProgramHeader { # MIPS-LLVM: Type: PT_MIPS_REGINFO (0x70000000) @@ -620,10 +581,10 @@ ProgramHeaders: ## CHECK how we dump RISCV specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_RISCV %s -o %triscv.elf -# RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-GNU +# RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=RISCV-GNU # RUN: llvm-readobj --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-LLVM -# RISCV-GNU: ATTRIBUTES 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# RISCV-GNU: ATTRIBUTES [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # RISCV-LLVM: ProgramHeader { # RISCV-LLVM: Type: PT_RISCV_ATTRIBUTES (0x70000003) -- Gitee From 32c13b52ef55d0b99055ab34c5e832be0c075557 Mon Sep 17 00:00:00 2001 From: Nikolai Kholiavin Date: Thu, 1 Dec 2022 21:02:20 +0000 Subject: [PATCH 4/4] [test][OHOS] Add back OHOS_RANDOMDATA elf header test, bump begin address by header size Change-Id: I88e651ae3db5e4fc6a57b12f53aa3b4269f8114a Signed-off-by: Nikolai Kholiavin --- .../llvm-readobj/ELF/program-headers.test | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/llvm/test/tools/llvm-readobj/ELF/program-headers.test b/llvm/test/tools/llvm-readobj/ELF/program-headers.test index 0f98d26e3ee9..d262000a4a48 100644 --- a/llvm/test/tools/llvm-readobj/ELF/program-headers.test +++ b/llvm/test/tools/llvm-readobj/ELF/program-headers.test @@ -19,19 +19,19 @@ # RUN: cmp %t.readobj-l.txt %t.readobj-segments.txt ## Check we are able to print program headers of different types. -# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x314 --check-prefixes=ELF32,MAPPING \ +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x334 --check-prefixes=ELF32,MAPPING \ # RUN: --match-full-lines --strict-whitespace --input-file=%t.readelf-l.txt -# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x314 --check-prefixes=ELF-LLVM \ +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x334 --check-prefixes=ELF-LLVM \ # RUN: --match-full-lines --input-file=%t.readobj-l.txt # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf # RUN: llvm-readelf -l %t64.elf | \ -# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefixes=ELF64,MAPPING \ +# RUN: FileCheck %s -D#%#x,FOO_BEGIN=0x580 --check-prefixes=ELF64,MAPPING \ # RUN: --strict-whitespace --match-full-lines -# RUN: llvm-readobj -l %t64.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 \ +# RUN: llvm-readobj -l %t64.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x580 \ # RUN: --check-prefixes=ELF-LLVM -# ELF32:There are 23 program headers, starting at offset 52 +# ELF32:There are 24 program headers, starting at offset 52 # ELF32-EMPTY: # ELF32-NEXT:Program Headers: # ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align @@ -59,9 +59,10 @@ # ELF32-NEXT: : 0x70000002 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 # ELF32-NEXT: : 0x70000003 [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 # ELF32-NEXT: : 0x7fffffff [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: OHOS_RANDOMDATA [[#%#.6x,FOO_BEGIN]] 0x00001000 0x00001000 0x00003 0x00003 0x1 # ELF32-EMPTY: -# ELF64:There are 23 program headers, starting at offset 64 +# ELF64:There are 24 program headers, starting at offset 64 # ELF64-EMPTY: # ELF64-NEXT:Program Headers: # ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align @@ -89,6 +90,7 @@ # ELF64-NEXT: : 0x70000002 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # ELF64-NEXT: : 0x70000003 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # ELF64-NEXT: : 0x7fffffff [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: OHOS_RANDOMDATA [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 # ELF64-EMPTY: # MAPPING: Section to Segment mapping: @@ -116,6 +118,7 @@ # MAPPING-NEXT: 20 .foo.begin .foo.end {{$}} # MAPPING-NEXT: 21 .foo.begin .foo.end {{$}} # MAPPING-NEXT: 22 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 23 .foo.begin .foo.end {{$}} # MAPPING-NEXT: None .unused .strtab .shstrtab {{$}} # ELF-LLVM: ProgramHeaders [ @@ -380,6 +383,17 @@ # ELF-LLVM-NEXT: ] # ELF-LLVM-NEXT: Alignment: 1 # ELF-LLVM-NEXT: } +# ELF-LLVM-NEXT: ProgramHeader { +# ELF-LLVM-NEXT: Type: PT_OHOS_RANDOMDATA (0x6788FC60) +# ELF-LLVM-NEXT: Offset: [[#%#.3X,FOO_BEGIN]] +# ELF-LLVM-NEXT: VirtualAddress: 0x1000 +# ELF-LLVM-NEXT: PhysicalAddress: 0x1000 +# ELF-LLVM-NEXT: FileSize: 3 +# ELF-LLVM-NEXT: MemSize: 3 +# ELF-LLVM-NEXT: Flags [ (0x0) +# ELF-LLVM-NEXT: ] +# ELF-LLVM-NEXT: Alignment: 1 +# ELF-LLVM-NEXT: } # ELF-LLVM-NEXT: ] --- !ELF @@ -543,10 +557,15 @@ ProgramHeaders: VAddr: 0x1000 FirstSec: .foo.begin LastSec: .foo.end +## Case 23: the PT_OHOS_RANDOMDATA segment. + - Type: 0x6788FC60 ## PT_OHOS_RANDOMDATA + VAddr: 0x1000 + FirstSec: .foo.begin + LastSec: .foo.end ## Check how we dump ARM specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf -# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=ARM-GNU +# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x580 --check-prefix=ARM-GNU # RUN: llvm-readobj --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-LLVM # ARM-GNU: : 0x70000000 [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 @@ -562,7 +581,7 @@ ProgramHeaders: ## Check how we dump MIPS specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf -# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=MIPS-GNU +# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x580 --check-prefix=MIPS-GNU # RUN: llvm-readobj --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-LLVM # MIPS-GNU: REGINFO [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 @@ -581,7 +600,7 @@ ProgramHeaders: ## CHECK how we dump RISCV specific program headers. # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_RISCV %s -o %triscv.elf -# RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x548 --check-prefix=RISCV-GNU +# RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s -D#%#x,FOO_BEGIN=0x580 --check-prefix=RISCV-GNU # RUN: llvm-readobj --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-LLVM # RISCV-GNU: ATTRIBUTES [[#%#.6x,FOO_BEGIN]] 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -- Gitee