Merge "Always use signed leb128 decoder"
This commit is contained in:
commit
ff18108981
@ -55,7 +55,7 @@
|
||||
#include "linker_block_allocator.h"
|
||||
#include "linker_debug.h"
|
||||
#include "linker_environ.h"
|
||||
#include "linker_leb128.h"
|
||||
#include "linker_sleb128.h"
|
||||
#include "linker_phdr.h"
|
||||
#include "linker_relocs.h"
|
||||
#include "linker_reloc_iterators.h"
|
||||
@ -2875,7 +2875,7 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
if (android_relocs_size_ > 3 &&
|
||||
android_relocs_[0] == 'A' &&
|
||||
android_relocs_[1] == 'P' &&
|
||||
(android_relocs_[2] == 'U' || android_relocs_[2] == 'S') &&
|
||||
android_relocs_[2] == 'S' &&
|
||||
android_relocs_[3] == '2') {
|
||||
DEBUG("[ android relocating %s ]", get_soname());
|
||||
|
||||
@ -2883,17 +2883,10 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
|
||||
const uint8_t* packed_relocs = android_relocs_ + 4;
|
||||
const size_t packed_relocs_size = android_relocs_size_ - 4;
|
||||
|
||||
if (android_relocs_[2] == 'U') {
|
||||
relocated = relocate(
|
||||
packed_reloc_iterator<leb128_decoder>(
|
||||
leb128_decoder(packed_relocs, packed_relocs_size)),
|
||||
global_group, local_group);
|
||||
} else { // android_relocs_[2] == 'S'
|
||||
relocated = relocate(
|
||||
packed_reloc_iterator<sleb128_decoder>(
|
||||
sleb128_decoder(packed_relocs, packed_relocs_size)),
|
||||
global_group, local_group);
|
||||
}
|
||||
relocated = relocate(
|
||||
packed_reloc_iterator<sleb128_decoder>(
|
||||
sleb128_decoder(packed_relocs, packed_relocs_size)),
|
||||
global_group, local_group);
|
||||
|
||||
if (!relocated) {
|
||||
return false;
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "linker_debug.h"
|
||||
#include "linker_relocs.h"
|
||||
#include "linker_reloc_iterators.h"
|
||||
#include "linker_leb128.h"
|
||||
#include "linker_sleb128.h"
|
||||
|
||||
template bool soinfo::relocate<plain_reloc_iterator>(plain_reloc_iterator&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
@ -41,11 +41,6 @@ template bool soinfo::relocate<packed_reloc_iterator<sleb128_decoder>>(
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
|
||||
template bool soinfo::relocate<packed_reloc_iterator<leb128_decoder>>(
|
||||
packed_reloc_iterator<leb128_decoder>&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
const soinfo_list_t& local_group);
|
||||
|
||||
template <typename ElfRelIteratorT>
|
||||
bool soinfo::relocate(ElfRelIteratorT&& rel_iterator,
|
||||
const soinfo_list_t& global_group,
|
||||
|
@ -14,42 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LINKER_LEB128_H
|
||||
#define _LINKER_LEB128_H
|
||||
#ifndef _LINKER_SLEB128_H
|
||||
#define _LINKER_SLEB128_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Helper classes for decoding LEB128, used in packed relocation data.
|
||||
// http://en.wikipedia.org/wiki/LEB128
|
||||
|
||||
class leb128_decoder {
|
||||
public:
|
||||
leb128_decoder(const uint8_t* buffer, size_t count)
|
||||
: current_(buffer), end_(buffer + count) { }
|
||||
|
||||
size_t pop_front() {
|
||||
size_t value = 0;
|
||||
|
||||
size_t shift = 0;
|
||||
uint8_t byte;
|
||||
|
||||
do {
|
||||
if (current_ >= end_) {
|
||||
__libc_fatal("leb128_decoder ran out of bounds");
|
||||
}
|
||||
byte = *current_++;
|
||||
value |= static_cast<size_t>(byte & 127) << shift;
|
||||
shift += 7;
|
||||
} while (byte & 128);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t* current_;
|
||||
const uint8_t* const end_;
|
||||
};
|
||||
|
||||
class sleb128_decoder {
|
||||
public:
|
||||
sleb128_decoder(const uint8_t* buffer, size_t count)
|
||||
@ -64,7 +36,7 @@ class sleb128_decoder {
|
||||
|
||||
do {
|
||||
if (current_ >= end_) {
|
||||
__libc_fatal("leb128_decoder ran out of bounds");
|
||||
__libc_fatal("sleb128_decoder ran out of bounds");
|
||||
}
|
||||
byte = *current_++;
|
||||
value |= (static_cast<size_t>(byte & 127) << shift);
|
||||
@ -83,5 +55,4 @@ class sleb128_decoder {
|
||||
const uint8_t* const end_;
|
||||
};
|
||||
|
||||
#endif // __LINKER_LEB128_H
|
||||
|
||||
#endif // __LINKER_SLEB128_H
|
Loading…
Reference in New Issue
Block a user