From: Vyacheslav Cherkashin Date: Thu, 15 Dec 2016 19:01:05 +0000 (+0300) Subject: Add support new elf_parser interface X-Git-Tag: submit/tizen_3.0/20170822.071124~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce73b24a7abc34d4d4a09b90371f4f9705f10388;p=platform%2Fcore%2Fsystem%2Fswap-manager.git Add support new elf_parser interface Change-Id: Ifcddd457accf9470286b9dacb041587bac7da7eb Signed-off-by: Vyacheslav Cherkashin --- diff --git a/daemon/Makefile b/daemon/Makefile index 8af111f..22d48e1 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -116,8 +116,7 @@ SRC_CPP := \ cpp/inst/AppInstCont.cpp \ cpp/inst/Anr.cpp \ \ - cpp/elf/File.cpp \ - cpp/elf/FileElf.cpp + cpp/elf/Elf.cpp TARGET = da_manager DASCRIPT = da_command diff --git a/daemon/cpp/elf/Elf.cpp b/daemon/cpp/elf/Elf.cpp new file mode 100644 index 0000000..0ece1f0 --- /dev/null +++ b/daemon/cpp/elf/Elf.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Vyacheslav Cherkashin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - Samsung RnD Institute Russia + */ + + +#include +#include +#include "Elf.h" +#include "swap_debug.h" + + +uint64_t Elf::plt(const std::string &path, const std::string &funcName) +{ + const struct elfp *e = elfp_init(path.c_str()); + if (!e) { + LOGE("Cannot init elfp, filename='%s'\n", path.c_str()); + return 0; + } + + size_t n = elfp_plt_count(e); + std::unique_ptr addr(new uint64_t[n]); + std::unique_ptr name(new const char *[n]); + + n = elfp_plt_fill(e, addr.get(), name.get()); + for (size_t i = 0; i < n; ++i) + if (funcName == name[i]) + return addr[i]; + + LOGE("PLT functino '%s' is not found\n", funcName.c_str()); + return 0; +} diff --git a/daemon/cpp/elf/Elf.h b/daemon/cpp/elf/Elf.h new file mode 100644 index 0000000..22a6516 --- /dev/null +++ b/daemon/cpp/elf/Elf.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Vyacheslav Cherkashin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - Samsung RnD Institute Russia + */ + +#ifndef ELF_H +#define ELF_H + + +#include +#include + + +class Elf +{ +public: + static uint64_t plt(const std::string &path, const std::string &funcName); +}; + + +#endif // ELF_H diff --git a/daemon/cpp/elf/File.cpp b/daemon/cpp/elf/File.cpp deleted file mode 100644 index d425822..0000000 --- a/daemon/cpp/elf/File.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "File.h" -#include -#include "swap_debug.h" - - -File::File() : - _f(0) -{ -} - -File::~File() -{ - close(); -} - -bool File::isOpen() -{ - return static_cast(_f); -} - -int File::open(const std::string &path) -{ - if (isOpen()) { - LOGE("already open flie '%s'\n", _path.c_str()); - return -EINVAL; - } - - _f = fopen(path.c_str(), "rb"); - if (_f == 0) { - LOGE("Failed to open file %s. Error %d!\n", path.c_str(), errno); - return errno; - } - - _path = path; - - int ret = doOpen(); - if (ret) - close(); - - return ret; -} - -void File::close() -{ - if (_f) { - fclose(_f); - _f = 0; - } -} - -int File::read(size_t pos, void *data, size_t size) -{ - if (fseek(_f, pos, SEEK_SET)) - return -ferror(_f); - - if (fread(data, 1, size, _f) != size) - return -ferror(_f); - - return 0; -} diff --git a/daemon/cpp/elf/File.h b/daemon/cpp/elf/File.h deleted file mode 100644 index 113d951..0000000 --- a/daemon/cpp/elf/File.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef FILE_H -#define FILE_H - - -#include -#include - - -class File -{ -public: - explicit File(); - virtual ~File(); - - int open(const std::string &path); - void close(); - int read(size_t pos, void *data, size_t size); - bool isOpen(); - std::string path() { return _path; } - -private: - virtual int doOpen() { return 0; } - - FILE *_f; - std::string _path; -}; - -#endif // FILE_H diff --git a/daemon/cpp/elf/FileElf.cpp b/daemon/cpp/elf/FileElf.cpp deleted file mode 100644 index 167e3a1..0000000 --- a/daemon/cpp/elf/FileElf.cpp +++ /dev/null @@ -1,387 +0,0 @@ -#include "FileElf.h" -#include -#include -#include -#include "swap_debug.h" -#include - - -static int checkFhdr(const Elf32_Ehdr *fhdr) -{ - if ((fhdr->e_ident[EI_MAG0] != ELFMAG0) || - (fhdr->e_ident[EI_MAG1] != ELFMAG1) || - (fhdr->e_ident[EI_MAG2] != ELFMAG2) || - (fhdr->e_ident[EI_MAG3] != ELFMAG3)) { - LOGE("Unsupported file format! e_ident: %02x %c %c %c.\n", - fhdr->e_ident[0], fhdr->e_ident[1], fhdr->e_ident[2], fhdr->e_ident[3]); - return -EINVAL; - } - - if (fhdr->e_ident[EI_CLASS] != ELFCLASS32) { - LOGE("Unsupported ELF file class: %u!\n", fhdr->e_ident[EI_CLASS]); - return -EINVAL; - } - - if (fhdr->e_ident[EI_VERSION] != EV_CURRENT) { - LOGE("Unsupported ELF header version: %u!\n", fhdr->e_ident[EI_VERSION]); - return -EINVAL; - } - - if (fhdr->e_ehsize < sizeof(Elf32_Ehdr)) { - LOGE("Invalid ELF header length: %hu\n!", fhdr->e_ehsize); - return -EINVAL; - } - - if (fhdr->e_version != EV_CURRENT) { - LOGE("Unsupported ELF version: %02x!\n", fhdr->e_version); - return -EINVAL; - } - - return 0; -} - -static bool checkStr(const char *str, const char *endBuf) -{ - for (const char *n = str; n < endBuf; ++n) - if (*n == '\0') - return true; - - return false; -} - -static uint32_t ror(uint32_t num, uint32_t rorN) -{ - uint32_t p = num % (1 << rorN); - - return (num >> rorN) + (p << (32 - rorN)); -} - - -FileElf::Data *FileElf::getSection(const Elf32_Shdr *shdr) -{ - Data *data = new Data; - if (data == 0) - return 0; - - data->size = shdr->sh_size; - data->data = ::operator new(data->size); - if (data->data == 0) { - delete data; - return 0; - } - - // read section - int ret = read(shdr->sh_offset, data->data, data->size); - if (ret) { - LOGE("Failed to read section. Error %d!\n", ret); - putSection(data); - return 0; - } - - data->shdr = shdr; - return data; -} - -FileElf::Data *FileElf::getSection(const std::string &name) -{ - const Elf32_Shdr *shdr = getShdr(name); - if (shdr == 0) { - LOGE("'%s' section is not found\n", name.c_str()); - return 0; - } - - return getSection(shdr); -} - -void FileElf::putSection(const Data *data) -{ - ::operator delete(data->data); - delete data; -} - -int FileElf::readSectionsInfo() -{ - Elf32_Shdr shdrStr; - size_t offsetStr = _fhdr.e_shoff + _fhdr.e_shstrndx * _fhdr.e_shentsize; - - _shdrMap.clear(); - - // read shstrtab section header - int ret = read(offsetStr, &shdrStr, sizeof(shdrStr)); - if (ret) { - LOGE("Failed to read section header 'shstrtab'. Error %d!\n", ret); - return ret; - } - - // check shstrtab section - if (shdrStr.sh_type != SHT_STRTAB) { - LOGE("Failed to find section header table entry for shstrtab with section names!\n"); - return -EINVAL; - } - - Data *data = getSection(&shdrStr); - if (data == 0) { - LOGE("get data 'shstrtab'' section %d\n"); - return -ENOMEM; - } - - const char *strData = reinterpret_cast(data->data); - const char *strDataEnd = strData + data->size; - if (strData == 0) { - ret = -ENOMEM; - goto putSect; - } - - for (int i = 0; i < _fhdr.e_shnum; ++i) { - Elf32_Shdr shdr; - size_t offset = _fhdr.e_shoff + i * _fhdr.e_shentsize; - - // read section header - int ret = read(offset, &shdr, sizeof(shdr)); - if (ret) { - LOGE("Failed to read section header %d. Error %d!\n", i, ret); - goto putSect; - } - - // read section name - const char *name = strData + shdr.sh_name; - if (checkStr(name, strDataEnd) == false) { - LOGE("Failed to get section name %d.!\n", i); - ret = -EINVAL; - goto putSect; - } - - _shdrMap[name] = shdr; - } - -putSect: - putSection(data); - return ret; -} - -const Elf32_Shdr *FileElf::getShdr(const std::string &name) -{ - ShdrMap::const_iterator it = _shdrMap.find(name); - if (it == _shdrMap.end()) - return 0; - - return &it->second; -} - -int FileElf::makeRelocMap(const uint8_t jump_slot) -{ - if (_relocMap.empty() == false) - return 0; - - static const char *nameRel = ".rel.plt"; - static const char *nameSym = ".dynsym"; - static const char *nameStr = ".dynstr"; - int ret = 0; - Data *dataRel; - Data *dataSym; - Data *dataStr; - Elf32_Rel *rel; - size_t relCnt; - Elf32_Sym *sym; - size_t symCnt; - const char *strEnd; - const char *strBegin; - - // section '.rel.plt' - dataRel = getSection(nameRel); - if (dataRel == 0) - return -ENOMEM; - - if (dataRel->size % sizeof(Elf32_Rel)) { - LOGE("'%s' section incorrect\n", nameRel); - ret = -EINVAL; - goto putSectRel; - } - rel = reinterpret_cast(dataRel->data); - relCnt = dataRel->size / sizeof(Elf32_Rel); - - // section '.dynsym' - dataSym = getSection(nameSym); - if (dataSym == 0) { - ret = -ENOMEM; - goto putSectRel; - } - - // section '.dynstr' - if (dataSym->size % sizeof(Elf32_Sym)) { - LOGE("'%s' section incorrect\n", nameSym); - ret = -EINVAL; - goto putSectSym; - } - sym = reinterpret_cast(dataSym->data); - symCnt = dataSym->size / sizeof(Elf32_Sym); - - dataStr = getSection(nameStr); - if (dataStr == 0) { - ret = -ENOMEM; - goto putSectSym; - } - strBegin = reinterpret_cast(dataStr->data); - strEnd = strBegin + dataStr->size; - - - for (size_t i = 0; i < relCnt; ++i) { - if (ELF32_R_TYPE(rel[i].r_info) == jump_slot) { - uint32_t offset = rel[i].r_offset; - uint32_t symId = ELF32_R_SYM(rel[i].r_info); - - if (symId >= symCnt) { - LOGE("symID is very big, symId=%lx\n", symId); - continue; - } - - uint32_t strOff = sym[symId].st_name; - - // read symbol name - const char *name = strBegin + strOff; - if (checkStr(name, strEnd) == false) { - LOGE("Failed to get symbol name %d.!\n", strOff); - continue; - } - - _relocMap[offset] = name; - } - } - - putSection(dataStr); -putSectSym: - putSection(dataSym); -putSectRel: - putSection(dataRel); - return ret; -} - -int FileElf::doGetAddrPltARM(const char *names[], uint32_t addrs[], size_t cnt) -{ - int ret = makeRelocMap(R_ARM_JUMP_SLOT); - if (ret) - return ret; - - static const char *secName = ".plt"; - const Data *data = getSection(secName); - if (data == 0) - return -ENOMEM; - - // for ARM - const uint32_t *inst = reinterpret_cast(data->data); - size_t instCnt = data->size / 4; - - typedef std::map FuncMap; - FuncMap funcMap; - uint32_t addr, n0, n1, n2, offset, rorN; - - - for (size_t i = 0, step = 0; i < instCnt; ++i) { - uint32_t p = inst[i] & 0xfffff000; - - switch (step) { - case 0: - if (p != 0xe28fc000) - continue; - - rorN = 2 * ((inst[i] % 0x1000) / 0x100); - addr = data->shdr->sh_addr + 4 * i; - n0 = ror(inst[i] % 0x100, rorN) + addr + 8; // add ip, pc, #a, b - step = 1; - break; - - case 1: - if (p != 0xe28cc000) { - step = 0; - continue; - } - - rorN = 2 * ((inst[i] % 0x1000) / 0x100); - n1 = ror(inst[i] % 0x100, rorN); // add ip, ip, #c, d - step = 2; - break; - - case 2: - if (p != 0xe5bcf000) { - step = 0; - continue; - } - - n2 = inst[i] % 0x1000; - offset = n0 + n1 + n2; // ldr pc, [ip, #e]! - - RelocMap::const_iterator it = _relocMap.find(offset); - if (it != _relocMap.end()) - funcMap[it->second] = addr; - - step = 0; - } - } - - // populate addrs - for (size_t i = 0; i < cnt; ++i) { - FuncMap::const_iterator it = funcMap.find(names[i]); - addrs[i] = it == funcMap.end() ? 0 : it->second; - } - - putSection(data); - return 0; -} - -int FileElf::doGetAddrPlt386(const char *names[], uint32_t addrs[], size_t cnt) -{ - Elf_Addr *elf_addrs = NULL; - std::string filename(path()); - int ret; - size_t i; - - ret = get_plt_addrs(filename.c_str(), names, cnt, &elf_addrs); - if (ret != 0) { - LOGE("Error getting .plt: %s\n", get_str_error(ret)); - free(elf_addrs); - return -EINVAL; - } - if (elf_addrs != NULL) { - for (i = 0; i < cnt; i++) { - addrs[i] = (uint32_t)elf_addrs[i]; - } - free(elf_addrs); - } - - return 0; -} - -int FileElf::getAddrPlt(const char *names[], uint32_t addrs[], size_t cnt) -{ - switch (_fhdr.e_machine) { - case EM_ARM: - return doGetAddrPltARM(names, addrs, cnt); - case EM_386: - return doGetAddrPlt386(names, addrs, cnt); - default: - LOGE("mach[%lu] is not support\n", _fhdr.e_machine); - } - - return -EINVAL; -} - -FileElf::FileElf() -{ -} - -int FileElf::doOpen() -{ - int ret = read(0, &_fhdr, sizeof(_fhdr)); - if (ret) { - LOGE("Failed to read file's header. Error %d!\n", ret); - return -errno; - } - - ret = checkFhdr(&_fhdr); - if (ret) - return ret; - - ret = readSectionsInfo(); - - return ret; -} diff --git a/daemon/cpp/elf/FileElf.h b/daemon/cpp/elf/FileElf.h deleted file mode 100644 index 1816f60..0000000 --- a/daemon/cpp/elf/FileElf.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef FILEELF_H -#define FILEELF_H - - -#include "File.h" -#include -#include - - -class FileElf : public File -{ -public: - FileElf(); - - int getAddrPlt(const char *names[], uint32_t addrs[], size_t cnt); - -private: - int doOpen(); - - struct Data { - size_t size; - void *data; - const Elf32_Shdr *shdr; - }; - - int readSectionsInfo(); - Data *getSection(const Elf32_Shdr *shdr); - Data *getSection(const std::string &name); - void putSection(const Data *data); - int makeRelocMap(const uint8_t jump_slot); - const Elf32_Shdr *getShdr(const std::string &name); - - int doGetAddrPltARM(const char *names[], uint32_t addrs[], size_t cnt); - int doGetAddrPlt386(const char *names[], uint32_t addrs[], size_t cnt); - - typedef std::map ShdrMap; - typedef std::map RelocMap; - - Elf32_Ehdr _fhdr; - ShdrMap _shdrMap; - RelocMap _relocMap; -}; - - -#endif // FILEELF_H diff --git a/daemon/cpp/features/feature_nsp.cpp b/daemon/cpp/features/feature_nsp.cpp index cd1055b..b8d01c6 100644 --- a/daemon/cpp/features/feature_nsp.cpp +++ b/daemon/cpp/features/feature_nsp.cpp @@ -35,7 +35,7 @@ #include "nsp_data.h" /* auto generate */ #include "inst/AppInstTizen.h" #include "inst/AppInstCont.h" -#include "elf/FileElf.h" +#include "elf/Elf.h" static const char path_enabled[] = "/sys/kernel/debug/swap/nsp/enabled"; @@ -108,27 +108,11 @@ static int nspDisable() return 0; } -static uint32_t getAddrPlt(const char *path, const char *name) -{ - FileElf elf; - - if (elf.open(path)) { - LOGE("cannot open ELF file '%s'\n", path); - return 0; - } - - uint32_t addr = 0; - int ret = elf.getAddrPlt(&name, &addr, 1); - elf.close(); - - return ret ? 0 : addr; -} - static int initLibAppCore() { uint32_t appcoreInitAddr = ADDR_APPCORE_INIT ? ADDR_APPCORE_INIT : - getAddrPlt(PATH_LIBAPPCORE_EFL, "appcore_init"); + Elf::plt(PATH_LIBAPPCORE_EFL, "appcore_init"); if (appcoreInitAddr == 0) { LOGE("not found 'appcore_init@plt' addr in '%s'\n", PATH_LIBAPPCORE_EFL); return -EINVAL; @@ -136,7 +120,7 @@ static int initLibAppCore() uint32_t elmRunAddr = ADDR_ELM_RUN_PLT ? ADDR_ELM_RUN_PLT : - getAddrPlt(PATH_LIBCAPI_APPFW_APPLICATION, "elm_run"); + Elf::plt(PATH_LIBCAPI_APPFW_APPLICATION, "elm_run"); if (elmRunAddr == 0) { LOGE("not found 'elm_run@plt' addr in '%s'\n", PATH_LIBAPPCORE_EFL); @@ -166,7 +150,7 @@ static int initLpad() { uint32_t dlopenAddr = ADDR_DLOPEN_PLT_LPAD ? ADDR_DLOPEN_PLT_LPAD : - getAddrPlt(PATH_LAUNCHPAD, "dlopen"); + Elf::plt(PATH_LAUNCHPAD, "dlopen"); if (dlopenAddr == 0) { LOGE("not found 'dlopen@plt' addr in '%s'\n", PATH_LAUNCHPAD); @@ -175,7 +159,7 @@ static int initLpad() uint32_t dlsymAddr = ADDR_DLSYM_PLT_LPAD ? ADDR_DLSYM_PLT_LPAD : - getAddrPlt(PATH_LAUNCHPAD, "dlsym"); + Elf::plt(PATH_LAUNCHPAD, "dlsym"); if (dlsymAddr == 0) { LOGE("not found 'dlsym@plt' addr in '%s'\n", PATH_LAUNCHPAD); diff --git a/daemon/cpp/features/feature_wsp.cpp b/daemon/cpp/features/feature_wsp.cpp index c19d9a7..e69f04f 100644 --- a/daemon/cpp/features/feature_wsp.cpp +++ b/daemon/cpp/features/feature_wsp.cpp @@ -33,7 +33,7 @@ #include "common.h" #include "swap_debug.h" #include "wsp_data.h" /* auto generate */ -#include "elf/FileElf.h" +#include "elf/Elf.h" static const char path_enabled[] = "/sys/kernel/debug/swap/wsp/enabled"; @@ -61,30 +61,11 @@ class FeatureWSP : public Feature { for (int ret, i = 0; i < wsp_data_cnt; ++i) { const std::string name (wsp_data[i].name); - unsigned long addr = wsp_data[i].addr; + uint64_t addr = wsp_data[i].addr; if (addr == 0) { - FileElf elf; - - ret = elf.open(chromium_path); - if (ret) { - LOGE("cannot open ELF file '%s'\n", chromium_path); - return ret; - } - std::string str = rmPlt(name); - const char *s = str.c_str(); - uint32_t a = 0; - - ret = elf.getAddrPlt(&s, &a, 1); - elf.close(); - - if (ret) { - LOGE("get plt addr for '%s'\n", s); - return ret; - } - - addr = a; + addr = Elf::plt(chromium_path, str); } if (addr == 0) { diff --git a/scripts/gen_loader_header.sh b/scripts/gen_loader_header.sh index 2ffb76f..9ac8a94 100755 --- a/scripts/gen_loader_header.sh +++ b/scripts/gen_loader_header.sh @@ -22,7 +22,7 @@ function print_loader() filename=$1 el=$(find $loader_library_path -regextype posix-extended -regex $loader_library_path$loader_library_pattern | head -n1) loader_lib=$(readlink -f $el) - addr=$(parse_elf $loader_lib -sa | grep "$loader_open_function\(@\|$\)" | head -1 | cut -f1 -d' ') + addr=$(parse_elf -f $loader_lib --addr_format=swap --syms | grep "$loader_open_function\(@\|$\)" | head -1 | cut -f1 -d' ') echo -e "/bin/echo \"$loader_lib\" > /sys/kernel/debug/swap/loader/loader/loader_path" >> $filename echo -e "/bin/echo 0x$addr > /sys/kernel/debug/swap/loader/loader/loader_offset" >> $filename @@ -55,5 +55,5 @@ print_loader $output print_linker $output # check addresses -grep 0x00000000 $output && echo "ERROR: generate loader info" >&2 && exit 1 +grep 0x0000000000000000 $output && echo "ERROR: generate loader info" >&2 && exit 1 echo 0 diff --git a/scripts/gen_nsp_data.sh b/scripts/gen_nsp_data.sh index 9863a3e..384e8b9 100755 --- a/scripts/gen_nsp_data.sh +++ b/scripts/gen_nsp_data.sh @@ -70,23 +70,23 @@ check_null_or_exit path_launchpad # get appcore_efl_init addr -addr_appcore_efl_init=$(parse_elf ${dpath_app_core_efl} -s appcore_efl_init) +addr_appcore_efl_init=$(parse_elf -f ${dpath_app_core_efl} --addr_format=swap --syms=appcore_efl_init) check_null_or_exit addr_appcore_efl_init # get __do_app addr if [ "$__tizen_product__" == "1" ]; then addr_do_app=0 else - addr_do_app=$(parse_elf ${dpath_app_core_efl} -s __do_app) + addr_do_app=$(parse_elf -f ${dpath_app_core_efl} --addr_format=swap --syms=__do_app) fi check_null_or_exit addr_do_app # libcapi-appfw-application.so if [ "$__tizen_product__" == "1" ]; then - addr_appcore_init=$(parse_elf $dpath_capi_appfw_application -r appcore_init) + addr_appcore_init=$(parse_elf -f $dpath_capi_appfw_application --addr_format=swap --plt=appcore_init) addr_appcore_init=${addr_appcore_init_plt:-0} else - addr_appcore_init=$(parse_elf $dpath_capi_appfw_application -s ui_app_init) + addr_appcore_init=$(parse_elf -f $dpath_capi_appfw_application --addr_format=swap --syms=ui_app_init) fi # PLT diff --git a/scripts/gen_wsi_prof.sh b/scripts/gen_wsi_prof.sh index 1b19a9b..8f7cdcf 100755 --- a/scripts/gen_wsi_prof.sh +++ b/scripts/gen_wsi_prof.sh @@ -1,20 +1,16 @@ #!/bin/bash -get_addrs() +get_addr() { - names=($@) - addrs=($(parse_elf ${lib_file} -sf ${names[@]})) + name=$1 + addr=($(parse_elf -f ${lib_file} --addr_format=swap --syms=${name})) - len=${#names[@]} - for (( i=0; i < ${len}; ++i)); do - name=${names[$i]} - addr=${addrs[$i]} - if [ -z "$addr" -o $((16#$addr)) -eq 0 ]; then - addr=0 - echo "ERROR: symbol '$name' not found" >&2 - fi - echo 0x$addr - done + if [ -z "$addr" -o $((16#$addr)) -eq 0 ]; then + addr=0 + echo "ERROR: symbol '$name' not found" >&2 + fi + + echo 0x$addr } script_dir=$(readlink -f $0 | xargs dirname) @@ -28,23 +24,15 @@ else lib_file=$(rpm -ql ${webkit_package_name}-debuginfo | grep "/usr/lib/debug/usr/lib/libchromium-ewk.so.debug" | head -1) fi -tmp=$(mktemp) - -func_names=() if [ "$__tizen_profile_name__" == "tv" ]; then - func_names+=(ewk_view_inspector_server_start) + inspector_name=ewk_view_inspector_server_start else - func_names+=(ewk_context_inspector_server_start) + inspector_name=ewk_context_inspector_server_start fi -func_names+=(_ZN2v88internal11ProfileNode14FindOrAddChildEPNS0_9CodeEntryE) - -addrs=(`get_addrs ${func_names[@]}`) - -inspector_addr=${addrs[0]} -tick_addr=${addrs[1]} -rm ${tmp} +inspector_addr=$(get_addr ${inspector_name}) +tick_addr=$(get_addr _ZN2v88internal11ProfileNode14FindOrAddChildEPNS0_9CodeEntryE) if [ -z "${inspector_addr}" -o -z "${tick_addr}" ]; then exit 1 diff --git a/scripts/gen_wsp_data.sh b/scripts/gen_wsp_data.sh index 387221b..34e6135 100755 --- a/scripts/gen_wsp_data.sh +++ b/scripts/gen_wsp_data.sh @@ -30,7 +30,7 @@ get_addrs() names=($@) len=${#names[@]} - if [[ "$param" == "-r" ]]; then + if [[ "$param" == "plt" ]]; then path_lib=$path_libchromium for (( i=0; i < ${len}; ++i)); do @@ -40,11 +40,9 @@ get_addrs() path_lib=$path_libchromium_debuginfo fi - addrs=($(parse_elf ${path_lib} -sf ${names[@]})) - for (( i=0; i < ${len}; ++i)); do name=${names[$i]} - addr=${addrs[$i]} + addr=$(parse_elf -f $path_lib --addr_format=swap --syms=$name | cut -f1 -d' ') if [ -z "$addr" -o $((16#$addr)) -eq 0 ]; then addr=0 echo "ERROR: symbol '$name' not found" >&2 @@ -73,12 +71,12 @@ add_func_plt() gen_array() { - addrs_plt=`get_addrs -r ${g_names_plt[@]}` + addrs_plt=`get_addrs plt ${g_names_plt[@]}` if [ $? -ne 0 ]; then exit 1; fi - addrs=`get_addrs -sf ${g_names[@]}` + addrs=`get_addrs syms ${g_names[@]}` if [ $? -ne 0 ]; then exit 1; fi