Commit e520e5da authored by yangguo's avatar yangguo Committed by Commit bot

[snapshot] do not embed string addresses in code.

Doing so in a -pie build would make the snapshot non-deterministic.

R=bmeurer@chromium.org
BUG=v8:5233

Review-Url: https://codereview.chromium.org/2178093003
Cr-Commit-Position: refs/heads/master@{#38042}
parent a5fae103
...@@ -2164,7 +2164,11 @@ void Assembler::stop(const char* msg, Condition cond, int32_t code) { ...@@ -2164,7 +2164,11 @@ void Assembler::stop(const char* msg, Condition cond, int32_t code) {
} else { } else {
svc(kStopCode + kMaxStopCode, cond); svc(kStopCode + kMaxStopCode, cond);
} }
emit(reinterpret_cast<Instr>(msg)); // Do not embed the message string address! We used to do this, but that
// made snapshots created from position-independent executable builds
// non-deterministic.
// TODO(yangguo): remove this field entirely.
nop();
} }
#else // def __arm__ #else // def __arm__
if (cond != al) { if (cond != al) {
......
...@@ -1364,16 +1364,10 @@ int Decoder::DecodeType7(Instruction* instr) { ...@@ -1364,16 +1364,10 @@ int Decoder::DecodeType7(Instruction* instr) {
if (instr->Bit(24) == 1) { if (instr->Bit(24) == 1) {
if (instr->SvcValue() >= kStopCode) { if (instr->SvcValue() >= kStopCode) {
Format(instr, "stop'cond 'svc"); Format(instr, "stop'cond 'svc");
// Also print the stop message. Its address is encoded out_buffer_pos_ += SNPrintF(
// in the following 4 bytes. out_buffer_ + out_buffer_pos_, "\n %p %08x",
out_buffer_pos_ += SNPrintF(out_buffer_ + out_buffer_pos_, reinterpret_cast<void*>(instr + Instruction::kInstrSize),
"\n %p %08x stop message: %s", *reinterpret_cast<uint32_t*>(instr + Instruction::kInstrSize));
reinterpret_cast<void*>(instr
+ Instruction::kInstrSize),
*reinterpret_cast<uint32_t*>(instr
+ Instruction::kInstrSize),
*reinterpret_cast<char**>(instr
+ Instruction::kInstrSize));
// We have decoded 2 * Instruction::kInstrSize bytes. // We have decoded 2 * Instruction::kInstrSize bytes.
return 2 * Instruction::kInstrSize; return 2 * Instruction::kInstrSize;
} else { } else {
......
...@@ -115,18 +115,11 @@ static void InitializeCoverage() { ...@@ -115,18 +115,11 @@ static void InitializeCoverage() {
void ArmDebugger::Stop(Instruction* instr) { void ArmDebugger::Stop(Instruction* instr) {
// Get the stop code. // Get the stop code.
uint32_t code = instr->SvcValue() & kStopCodeMask; uint32_t code = instr->SvcValue() & kStopCodeMask;
// Retrieve the encoded address, which comes just after this stop.
char* msg = *reinterpret_cast<char**>(sim_->get_pc()
+ Instruction::kInstrSize);
// Update this stop description.
if (sim_->isWatchedStop(code) && !sim_->watched_stops_[code].desc) {
sim_->watched_stops_[code].desc = msg;
}
// Print the stop message and code if it is not the default code. // Print the stop message and code if it is not the default code.
if (code != kMaxStopCode) { if (code != kMaxStopCode) {
PrintF("Simulator hit stop %u: %s\n", code, msg); PrintF("Simulator hit stop %u\n", code);
} else { } else {
PrintF("Simulator hit %s\n", msg); PrintF("Simulator hit\n");
} }
sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize); sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize);
Debug(); Debug();
......
...@@ -1974,7 +1974,11 @@ void Assembler::stop(const char* msg, uint32_t code) { ...@@ -1974,7 +1974,11 @@ void Assembler::stop(const char* msg, uint32_t code) {
// The Simulator will handle the stop instruction and get the message address. // The Simulator will handle the stop instruction and get the message address.
// On MIPS stop() is just a special kind of break_(). // On MIPS stop() is just a special kind of break_().
break_(code, true); break_(code, true);
emit(reinterpret_cast<Instr>(msg)); // Do not embed the message string address! We used to do this, but that
// made snapshots created from position-independent executable builds
// non-deterministic.
// TODO(yangguo): remove this field entirely.
nop();
#endif #endif
} }
......
...@@ -138,14 +138,7 @@ static void InitializeCoverage() {} ...@@ -138,14 +138,7 @@ static void InitializeCoverage() {}
void MipsDebugger::Stop(Instruction* instr) { void MipsDebugger::Stop(Instruction* instr) {
// Get the stop code. // Get the stop code.
uint32_t code = instr->Bits(25, 6); uint32_t code = instr->Bits(25, 6);
// Retrieve the encoded address, which comes just after this stop. PrintF("Simulator hit (%u)\n", code);
char* msg = *reinterpret_cast<char**>(sim_->get_pc() +
Instruction::kInstrSize);
// Update this stop description.
if (!sim_->watched_stops_[code].desc) {
sim_->watched_stops_[code].desc = msg;
}
PrintF("Simulator hit %s (%u)\n", msg, code);
sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize); sim_->set_pc(sim_->get_pc() + 2 * Instruction::kInstrSize);
Debug(); Debug();
} }
......
...@@ -2225,7 +2225,11 @@ void Assembler::stop(const char* msg, uint32_t code) { ...@@ -2225,7 +2225,11 @@ void Assembler::stop(const char* msg, uint32_t code) {
// The Simulator will handle the stop instruction and get the message address. // The Simulator will handle the stop instruction and get the message address.
// On MIPS stop() is just a special kind of break_(). // On MIPS stop() is just a special kind of break_().
break_(code, true); break_(code, true);
emit(reinterpret_cast<uint64_t>(msg)); // Do not embed the message string address! We used to do this, but that
// made snapshots created from position-independent executable builds
// non-deterministic.
// TODO(yangguo): remove this field entirely.
nop();
#endif #endif
} }
......
...@@ -803,13 +803,11 @@ int Decoder::DecodeBreakInstr(Instruction* instr) { ...@@ -803,13 +803,11 @@ int Decoder::DecodeBreakInstr(Instruction* instr) {
// This is stop(msg). // This is stop(msg).
Format(instr, "break, code: 'code"); Format(instr, "break, code: 'code");
out_buffer_pos_ += SNPrintF( out_buffer_pos_ += SNPrintF(
out_buffer_ + out_buffer_pos_, out_buffer_ + out_buffer_pos_, "\n%p %08" PRIx64,
"\n%p %08" PRIx64 " stop msg: %s",
static_cast<void*>( static_cast<void*>(
reinterpret_cast<int32_t*>(instr + Instruction::kInstrSize)), reinterpret_cast<int32_t*>(instr + Instruction::kInstrSize)),
reinterpret_cast<uint64_t>( reinterpret_cast<uint64_t>(
*reinterpret_cast<char**>(instr + Instruction::kInstrSize)), *reinterpret_cast<char**>(instr + Instruction::kInstrSize)));
*reinterpret_cast<char**>(instr + Instruction::kInstrSize));
// Size 3: the break_ instr, plus embedded 64-bit char pointer. // Size 3: the break_ instr, plus embedded 64-bit char pointer.
return 3 * Instruction::kInstrSize; return 3 * Instruction::kInstrSize;
} else { } else {
......
...@@ -152,14 +152,7 @@ static void InitializeCoverage() {} ...@@ -152,14 +152,7 @@ static void InitializeCoverage() {}
void MipsDebugger::Stop(Instruction* instr) { void MipsDebugger::Stop(Instruction* instr) {
// Get the stop code. // Get the stop code.
uint32_t code = instr->Bits(25, 6); uint32_t code = instr->Bits(25, 6);
// Retrieve the encoded address, which comes just after this stop. PrintF("Simulator hit (%u)\n", code);
char* msg = *reinterpret_cast<char**>(sim_->get_pc() +
Instruction::kInstrSize);
// Update this stop description.
if (!sim_->watched_stops_[code].desc) {
sim_->watched_stops_[code].desc = msg;
}
PrintF("Simulator hit %s (%u)\n", msg, code);
// TODO(yuyin): 2 -> 3? // TODO(yuyin): 2 -> 3?
sim_->set_pc(sim_->get_pc() + 3 * Instruction::kInstrSize); sim_->set_pc(sim_->get_pc() + 3 * Instruction::kInstrSize);
Debug(); Debug();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment