Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: tools/relocation_packer/src/elf_file.cc

Issue 669813003: Update from chromium https://crrev.com/301725/ (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/relocation_packer/src/elf_file.h ('k') | tools/valgrind/chrome_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/relocation_packer/src/elf_file.cc
diff --git a/tools/relocation_packer/src/elf_file.cc b/tools/relocation_packer/src/elf_file.cc
index 62c390a2bde39232462df9ef2858cc293005c4b4..3ffccecd7c4bc4d87a34194f7416b04b141524ee 100644
--- a/tools/relocation_packer/src/elf_file.cc
+++ b/tools/relocation_packer/src/elf_file.cc
@@ -71,9 +71,10 @@ Elf_Data* GetSectionData(Elf_Scn* section) {
// Rewrite section data. Allocates new data and makes it the data element's
// buffer. Relies on program exit to free allocated data.
-void RewriteSectionData(Elf_Data* data,
+void RewriteSectionData(Elf_Scn* section,
const void* section_data,
size_t size) {
+ Elf_Data* data = GetSectionData(section);
CHECK(size == data->d_size);
uint8_t* area = new uint8_t[size];
memcpy(area, section_data, size);
@@ -797,7 +798,7 @@ void AdjustDynamicSectionForHole(Elf_Scn* dynamic_section,
void* section_data = &dynamics[0];
size_t bytes = dynamics.size() * sizeof(dynamics[0]);
- RewriteSectionData(data, section_data, bytes);
+ RewriteSectionData(dynamic_section, section_data, bytes);
}
// Resize a section. If the new size is larger than the current size, open
@@ -952,7 +953,7 @@ bool ElfFile::PackRelocations() {
relocations_base + data->d_size / sizeof(relocations[0]));
LOG(INFO) << "Relocations : REL";
- return PackTypedRelocations<ELF::Rel>(relocations, data);
+ return PackTypedRelocations<ELF::Rel>(relocations);
}
if (relocations_type_ == RELA) {
@@ -964,7 +965,7 @@ bool ElfFile::PackRelocations() {
relocations_base + data->d_size / sizeof(relocations[0]));
LOG(INFO) << "Relocations : RELA";
- return PackTypedRelocations<ELF::Rela>(relocations, data);
+ return PackTypedRelocations<ELF::Rela>(relocations);
}
NOTREACHED();
@@ -973,8 +974,7 @@ bool ElfFile::PackRelocations() {
// Helper for PackRelocations(). Rel type is one of ELF::Rel or ELF::Rela.
template <typename Rel>
-bool ElfFile::PackTypedRelocations(const std::vector<Rel>& relocations,
- Elf_Data* data) {
+bool ElfFile::PackTypedRelocations(const std::vector<Rel>& relocations) {
// Filter relocations into those that are relative and others.
std::vector<Rel> relative_relocations;
std::vector<Rel> other_relocations;
@@ -1085,17 +1085,16 @@ bool ElfFile::PackTypedRelocations(const std::vector<Rel>& relocations,
const void* section_data = &other_relocations[0];
const size_t bytes = other_relocations.size() * sizeof(other_relocations[0]);
ResizeSection<Rel>(elf_, relocations_section_, bytes);
- RewriteSectionData(data, section_data, bytes);
+ RewriteSectionData(relocations_section_, section_data, bytes);
// Rewrite the current packed android relocations section to hold the packed
// relative relocations.
- data = GetSectionData(android_relocations_section_);
ResizeSection<Rel>(elf_, android_relocations_section_, packed_bytes);
- RewriteSectionData(data, packed_data, packed_bytes);
+ RewriteSectionData(android_relocations_section_, packed_data, packed_bytes);
// Rewrite .dynamic to include two new tags describing the packed android
// relocations.
- data = GetSectionData(dynamic_section_);
+ Elf_Data* data = GetSectionData(dynamic_section_);
const ELF::Dyn* dynamic_base = reinterpret_cast<ELF::Dyn*>(data->d_buf);
std::vector<ELF::Dyn> dynamics(
dynamic_base,
@@ -1116,7 +1115,7 @@ bool ElfFile::PackTypedRelocations(const std::vector<Rel>& relocations,
}
const void* dynamics_data = &dynamics[0];
const size_t dynamics_bytes = dynamics.size() * sizeof(dynamics[0]);
- RewriteSectionData(data, dynamics_data, dynamics_bytes);
+ RewriteSectionData(dynamic_section_, dynamics_data, dynamics_bytes);
Flush();
return true;
@@ -1149,7 +1148,7 @@ bool ElfFile::UnpackRelocations() {
// Signature is APR1, unpack relocations.
CHECK(relocations_type_ == REL);
LOG(INFO) << "Relocations : REL";
- return UnpackTypedRelocations<ELF::Rel>(packed, data);
+ return UnpackTypedRelocations<ELF::Rel>(packed);
}
if (packed.size() > 3 &&
@@ -1160,7 +1159,7 @@ bool ElfFile::UnpackRelocations() {
// Signature is APA1, unpack relocations with addends.
CHECK(relocations_type_ == RELA);
LOG(INFO) << "Relocations : RELA";
- return UnpackTypedRelocations<ELF::Rela>(packed, data);
+ return UnpackTypedRelocations<ELF::Rela>(packed);
}
LOG(ERROR) << "Packed relative relocations not found (not packed?)";
@@ -1169,8 +1168,7 @@ bool ElfFile::UnpackRelocations() {
// Helper for UnpackRelocations(). Rel type is one of ELF::Rel or ELF::Rela.
template <typename Rel>
-bool ElfFile::UnpackTypedRelocations(const std::vector<uint8_t>& packed,
- Elf_Data* data) {
+bool ElfFile::UnpackTypedRelocations(const std::vector<uint8_t>& packed) {
// Unpack the data to re-materialize the relative relocations.
const size_t packed_bytes = packed.size() * sizeof(packed[0]);
LOG(INFO) << "Packed relative: " << packed_bytes << " bytes";
@@ -1182,7 +1180,7 @@ bool ElfFile::UnpackTypedRelocations(const std::vector<uint8_t>& packed,
LOG(INFO) << "Unpacked relative: " << unpacked_bytes << " bytes";
// Retrieve the current dynamic relocations section data.
- data = GetSectionData(relocations_section_);
+ Elf_Data* data = GetSectionData(relocations_section_);
// Interpret data as relocations.
const Rel* relocations_base = reinterpret_cast<Rel*>(data->d_buf);
@@ -1234,17 +1232,17 @@ bool ElfFile::UnpackTypedRelocations(const std::vector<uint8_t>& packed,
const size_t bytes = relocations.size() * sizeof(relocations[0]);
LOG(INFO) << "Total : " << relocations.size() << " entries";
ResizeSection<Rel>(elf_, relocations_section_, bytes);
- RewriteSectionData(data, section_data, bytes);
+ RewriteSectionData(relocations_section_, section_data, bytes);
// Nearly empty the current packed android relocations section. Leaves a
// four-byte stub so that some data remains allocated to the section.
// This is a convenience which allows us to re-pack this file again without
// having to remove the section and then add a new small one with objcopy.
// The way we resize sections relies on there being some data in a section.
- data = GetSectionData(android_relocations_section_);
ResizeSection<Rel>(
elf_, android_relocations_section_, sizeof(kStubIdentifier));
- RewriteSectionData(data, &kStubIdentifier, sizeof(kStubIdentifier));
+ RewriteSectionData(
+ android_relocations_section_, &kStubIdentifier, sizeof(kStubIdentifier));
// Rewrite .dynamic to remove two tags describing packed android relocations.
data = GetSectionData(dynamic_section_);
@@ -1256,7 +1254,7 @@ bool ElfFile::UnpackTypedRelocations(const std::vector<uint8_t>& packed,
RemoveDynamicEntry(DT_ANDROID_REL_SIZE, &dynamics);
const void* dynamics_data = &dynamics[0];
const size_t dynamics_bytes = dynamics.size() * sizeof(dynamics[0]);
- RewriteSectionData(data, dynamics_data, dynamics_bytes);
+ RewriteSectionData(dynamic_section_, dynamics_data, dynamics_bytes);
Flush();
return true;
« no previous file with comments | « tools/relocation_packer/src/elf_file.h ('k') | tools/valgrind/chrome_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698