summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2019-03-22 17:06:28 +0000
committer David Srbecky <dsrbecky@google.com> 2019-03-25 10:59:19 +0000
commit50928116be503deed341fbc84c0647d5687b12a1 (patch)
tree2ab09470c05eff72860eb8df14dfcc1fba002ec4
parentb9c29f625bc27968d80f9eafa988dc14af0a1c28 (diff)
Move elf_utils.h to libelffile library as well.
Also move some of our ART-specific utils form elf.h. Bug: 73344075 Test: generated oat files on host are identical. Change-Id: I587afc30875b9ddb57220fb3d4e764f9bb7a0e25
-rw-r--r--compiler/debug/elf_debug_writer.cc2
-rw-r--r--dex2oat/linker/elf_writer_quick.cc5
-rw-r--r--dex2oat/linker/image_writer.cc2
-rw-r--r--libelffile/Android.bp7
-rw-r--r--libelffile/elf/elf_builder.h20
-rw-r--r--libelffile/elf/elf_debug_reader.h9
-rw-r--r--libelffile/elf/elf_utils.h (renamed from runtime/elf_utils.h)41
-rw-r--r--runtime/Android.bp17
-rw-r--r--runtime/elf_file.cc2
-rw-r--r--runtime/elf_file.h3
-rw-r--r--runtime/elf_file_impl.h3
-rw-r--r--runtime/oat_file.cc2
12 files changed, 76 insertions, 37 deletions
diff --git a/compiler/debug/elf_debug_writer.cc b/compiler/debug/elf_debug_writer.cc
index cc74717edb..10f673b2d6 100644
--- a/compiler/debug/elf_debug_writer.cc
+++ b/compiler/debug/elf_debug_writer.cc
@@ -30,9 +30,9 @@
#include "debug/elf_symtab_writer.h"
#include "debug/method_debug_info.h"
#include "dwarf/dwarf_constants.h"
-#include "elf/elf.h"
#include "elf/elf_builder.h"
#include "elf/elf_debug_reader.h"
+#include "elf/elf_utils.h"
#include "elf/xz_utils.h"
#include "oat.h"
#include "stream/vector_output_stream.h"
diff --git a/dex2oat/linker/elf_writer_quick.cc b/dex2oat/linker/elf_writer_quick.cc
index 65aa5a9887..6463445e74 100644
--- a/dex2oat/linker/elf_writer_quick.cc
+++ b/dex2oat/linker/elf_writer_quick.cc
@@ -16,8 +16,8 @@
#include "elf_writer_quick.h"
-#include <openssl/sha.h>
#include <memory>
+#include <openssl/sha.h>
#include <unordered_map>
#include <unordered_set>
@@ -31,9 +31,8 @@
#include "debug/elf_debug_writer.h"
#include "debug/method_debug_info.h"
#include "driver/compiler_options.h"
-#include "elf/elf.h"
#include "elf/elf_builder.h"
-#include "elf_utils.h"
+#include "elf/elf_utils.h"
#include "stream/buffered_output_stream.h"
#include "stream/file_output_stream.h"
#include "thread-current-inl.h"
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index 96d54cd22c..2329554945 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -40,8 +40,8 @@
#include "dex/dex_file-inl.h"
#include "dex/dex_file_types.h"
#include "driver/compiler_options.h"
+#include "elf/elf_utils.h"
#include "elf_file.h"
-#include "elf_utils.h"
#include "gc/accounting/card_table-inl.h"
#include "gc/accounting/heap_bitmap.h"
#include "gc/accounting/space_bitmap-inl.h"
diff --git a/libelffile/Android.bp b/libelffile/Android.bp
index 60499dc379..d8db915b52 100644
--- a/libelffile/Android.bp
+++ b/libelffile/Android.bp
@@ -14,13 +14,6 @@
// limitations under the License.
//
-// Needed to import elf.h in the runtime.
-cc_library_headers {
- name: "libelffile-headers",
- host_supported: true,
- export_include_dirs: ["."],
-}
-
art_cc_defaults {
name: "libelffile-defaults",
host_supported: true,
diff --git a/libelffile/elf/elf_builder.h b/libelffile/elf/elf_builder.h
index 1f6781a37b..5af830d139 100644
--- a/libelffile/elf/elf_builder.h
+++ b/libelffile/elf/elf_builder.h
@@ -26,7 +26,7 @@
#include "base/casts.h"
#include "base/leb128.h"
#include "base/unix_file/fd_file.h"
-#include "elf/elf.h"
+#include "elf/elf_utils.h"
#include "stream/error_delaying_output_stream.h"
namespace art {
@@ -372,8 +372,8 @@ class ElfBuilder final {
sym.st_shndx = section->GetSectionIndex();
// The sh_info file must be set to index one-past the last local symbol.
- if (sym.getBinding() == STB_LOCAL) {
- DCHECK_EQ(syms_.back().getBinding(), STB_LOCAL);
+ if (ELF_ST_BIND(sym.st_info) == STB_LOCAL) {
+ DCHECK_EQ(ELF_ST_BIND(syms_.back().st_info), STB_LOCAL);
this->header_.sh_info = syms_.size() + 1;
}
@@ -741,13 +741,13 @@ class ElfBuilder final {
hash_.AllocateVirtualMemory(hash_.GetCacheSize());
Elf_Dyn dyns[] = {
- { DT_HASH, { hash_.GetAddress() } },
- { DT_STRTAB, { dynstr_.GetAddress() } },
- { DT_SYMTAB, { dynsym_.GetAddress() } },
- { DT_SYMENT, { sizeof(Elf_Sym) } },
- { DT_STRSZ, { dynstr_.GetCacheSize() } },
- { DT_SONAME, { soname_offset } },
- { DT_NULL, { 0 } },
+ { .d_tag = DT_HASH, .d_un.d_ptr = hash_.GetAddress() },
+ { .d_tag = DT_STRTAB, .d_un.d_ptr = dynstr_.GetAddress() },
+ { .d_tag = DT_SYMTAB, .d_un.d_ptr = dynsym_.GetAddress() },
+ { .d_tag = DT_SYMENT, .d_un.d_ptr = sizeof(Elf_Sym) },
+ { .d_tag = DT_STRSZ, .d_un.d_ptr = dynstr_.GetCacheSize() },
+ { .d_tag = DT_SONAME, .d_un.d_ptr = soname_offset },
+ { .d_tag = DT_NULL, .d_un.d_ptr = 0 },
};
dynamic_.Add(&dyns, sizeof(dyns));
dynamic_.AllocateVirtualMemory(dynamic_.GetCacheSize());
diff --git a/libelffile/elf/elf_debug_reader.h b/libelffile/elf/elf_debug_reader.h
index 3b3c050f53..2b0303741b 100644
--- a/libelffile/elf/elf_debug_reader.h
+++ b/libelffile/elf/elf_debug_reader.h
@@ -19,7 +19,7 @@
#include "base/array_ref.h"
#include "dwarf/headers.h"
-#include "elf/elf.h"
+#include "elf/elf_utils.h"
#include "xz_utils.h"
#include <map>
@@ -61,7 +61,10 @@ class ElfDebugReader {
explicit ElfDebugReader(ArrayRef<const uint8_t> file) : file_(file) {
header_ = Read<Elf_Ehdr>(/*offset=*/ 0);
- CHECK(header_->checkMagic());
+ CHECK_EQ(header_->e_ident[0], ELFMAG0);
+ CHECK_EQ(header_->e_ident[1], ELFMAG1);
+ CHECK_EQ(header_->e_ident[2], ELFMAG2);
+ CHECK_EQ(header_->e_ident[3], ELFMAG3);
CHECK_EQ(header_->e_ehsize, sizeof(Elf_Ehdr));
CHECK_EQ(header_->e_shentsize, sizeof(Elf_Shdr));
@@ -100,7 +103,7 @@ class ElfDebugReader {
CHECK_EQ(symtab->sh_entsize, sizeof(Elf_Sym));
size_t count = symtab->sh_size / sizeof(Elf_Sym);
for (const Elf_Sym& symbol : Read<Elf_Sym>(symtab->sh_offset, count)) {
- if (symbol.getType() == STT_FUNC && &sections_[symbol.st_shndx] == text) {
+ if (ELF_ST_TYPE(symbol.st_info) == STT_FUNC && &sections_[symbol.st_shndx] == text) {
visit_sym(symbol, Read<char>(strtab->sh_offset + symbol.st_name));
}
}
diff --git a/runtime/elf_utils.h b/libelffile/elf/elf_utils.h
index deb081d590..7aae2bad2c 100644
--- a/runtime/elf_utils.h
+++ b/libelffile/elf/elf_utils.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ART_RUNTIME_ELF_UTILS_H_
-#define ART_RUNTIME_ELF_UTILS_H_
+#ifndef ART_LIBELFFILE_ELF_ELF_UTILS_H_
+#define ART_LIBELFFILE_ELF_ELF_UTILS_H_
#include <sys/cdefs.h>
@@ -26,6 +26,41 @@
namespace art {
+struct ElfTypes32 {
+ typedef Elf32_Addr Addr;
+ typedef Elf32_Off Off;
+ typedef Elf32_Half Half;
+ typedef Elf32_Word Word;
+ typedef Elf32_Sword Sword;
+ typedef Elf32_Ehdr Ehdr;
+ typedef Elf32_Shdr Shdr;
+ typedef Elf32_Sym Sym;
+ typedef Elf32_Rel Rel;
+ typedef Elf32_Rela Rela;
+ typedef Elf32_Phdr Phdr;
+ typedef Elf32_Dyn Dyn;
+};
+
+struct ElfTypes64 {
+ typedef Elf64_Addr Addr;
+ typedef Elf64_Off Off;
+ typedef Elf64_Half Half;
+ typedef Elf64_Word Word;
+ typedef Elf64_Sword Sword;
+ typedef Elf64_Xword Xword;
+ typedef Elf64_Sxword Sxword;
+ typedef Elf64_Ehdr Ehdr;
+ typedef Elf64_Shdr Shdr;
+ typedef Elf64_Sym Sym;
+ typedef Elf64_Rel Rel;
+ typedef Elf64_Rela Rela;
+ typedef Elf64_Phdr Phdr;
+ typedef Elf64_Dyn Dyn;
+};
+
+#define ELF_ST_BIND(x) ((x) >> 4)
+#define ELF_ST_TYPE(x) ((x) & 0xf)
+
// Architecture dependent flags for the ELF header.
#define EF_ARM_EABI_VER5 0x05000000
#define EF_MIPS_ABI_O32 0x00001000
@@ -169,4 +204,4 @@ static inline bool IsDynamicSectionPointer(Elf32_Word d_tag, Elf32_Word e_machin
} // namespace art
-#endif // ART_RUNTIME_ELF_UTILS_H_
+#endif // ART_LIBELFFILE_ELF_ELF_UTILS_H_
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 937885a0d1..db99631370 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -391,7 +391,6 @@ libart_cc_defaults {
"libicuuc_headers",
"libnativehelper_header_only",
"jni_platform_headers",
- "libelffile-headers",
],
shared_libs: [
"libartpalette",
@@ -444,7 +443,10 @@ cc_defaults {
"libdexfile_static_defaults",
"libprofile_static_defaults",
],
- static_libs: ["libart"],
+ static_libs: [
+ "libart",
+ "libelffile",
+ ],
}
cc_defaults {
@@ -455,7 +457,10 @@ cc_defaults {
"libdexfiled_static_defaults",
"libprofiled_static_defaults",
],
- static_libs: ["libartd"],
+ static_libs: [
+ "libartd",
+ "libelffiled",
+ ],
}
gensrcs {
@@ -511,6 +516,9 @@ art_cc_library {
},
whole_static_libs: [
],
+ static_libs: [
+ "libelffile",
+ ],
shared_libs: [
"libartbase",
"libdexfile",
@@ -536,6 +544,9 @@ art_cc_library {
],
whole_static_libs: [
],
+ static_libs: [
+ "libelffiled",
+ ],
shared_libs: [
"libartbased",
"libdexfiled",
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 4e5fe5ff0b..12c33dead8 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -29,8 +29,8 @@
#include "base/stl_util.h"
#include "base/unix_file/fd_file.h"
#include "base/utils.h"
+#include "elf/elf_utils.h"
#include "elf_file_impl.h"
-#include "elf_utils.h"
namespace art {
diff --git a/runtime/elf_file.h b/runtime/elf_file.h
index e2094bcd59..ccfd445ca3 100644
--- a/runtime/elf_file.h
+++ b/runtime/elf_file.h
@@ -22,8 +22,7 @@
#include "base/macros.h"
#include "base/os.h"
-// Explicitly include our own elf.h to avoid Linux and other dependencies.
-#include "elf/elf.h"
+#include "elf/elf_utils.h"
namespace art {
diff --git a/runtime/elf_file_impl.h b/runtime/elf_file_impl.h
index c1899d27f8..9900c76e40 100644
--- a/runtime/elf_file_impl.h
+++ b/runtime/elf_file_impl.h
@@ -22,9 +22,8 @@
#include <type_traits>
#include <vector>
-// Explicitly include our own elf.h to avoid Linux and other dependencies.
-#include "elf/elf.h"
#include "base/mem_map.h"
+#include "elf/elf_utils.h"
namespace art {
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 028c22a0a1..dcca04c9f9 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -58,8 +58,8 @@
#include "dex/standard_dex_file.h"
#include "dex/type_lookup_table.h"
#include "dex/utf-inl.h"
+#include "elf/elf_utils.h"
#include "elf_file.h"
-#include "elf_utils.h"
#include "gc_root.h"
#include "gc/heap.h"
#include "gc/space/image_space.h"