Commit 48d964af authored by Matheus Marchini's avatar Matheus Marchini Committed by Commit Bot

snapshot: add size info for builtins on Posix

Lack of size information can cause debugging and observability tools to
misbehave or to fail. We can see the size for all builtins is zero with
objdump:

  $ objdump -t d8 | grep Builtins_ArgumentsAdaptorTrampoline
  0000000001084a00 l     F .text  0000000000000000              Builtins_ArgumentsAdaptorTrampoline
                                  ^
                                  Size is zero

Tools like bpftrace rely on the function size to guarantee a tracepoint
is added within function boundaries. Without size information, those
tools can't guarantee a tracepoint will be added safely.

Add .size directive for each builtin function, as described in
https://sourceware.org/binutils/docs-2.24/as/Size.html#Size, to fix this
issue. We can see with objdump that the size is properly set:

  $ objdump -t d8 | grep Builtins_ArgumentsAdaptorTrampoline
  00000000010bf820 l     F .text  0000000000000140              Builtins_ArgumentsAdaptorTrampoline

R=bmeurer@chromium.org, hpayer@chromium.org, verwaest@chromium.org, yangguo@chromium.org

Change-Id: I4cd2b0a12b629498dd9d7465cc1002dda37028c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1898807
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64824}
parent 73110f6e
......@@ -31,7 +31,8 @@ void EmbeddedFileWriter::WriteBuiltin(PlatformEmbeddedFileWriterBase* w,
// Isolate::SetEmbeddedBlob that the blob layout remains unchanged, i.e.
// that labels do not insert bytes into the middle of the blob byte
// stream.
w->DeclareFunctionBegin(builtin_symbol.begin());
w->DeclareFunctionBegin(builtin_symbol.begin(),
blob->InstructionSizeOfBuiltin(builtin_id));
const std::vector<byte>& current_positions = source_positions_[builtin_id];
// The code below interleaves bytes of assembly code for the builtin
......
......@@ -82,7 +82,9 @@ void PlatformEmbeddedFileWriterAIX::SourceInfo(int fileid, const char* filename,
fprintf(fp_, ".xline %d, \"%s\"\n", line, filename);
}
void PlatformEmbeddedFileWriterAIX::DeclareFunctionBegin(const char* name) {
// TODO(mmarchini): investigate emitting size annotations for AIX
void PlatformEmbeddedFileWriterAIX::DeclareFunctionBegin(const char* name,
uint32_t size) {
Newline();
DeclareSymbolGlobal(name);
fprintf(fp_, ".csect %s[DS]\n", name); // function descriptor
......
......@@ -34,7 +34,7 @@ class PlatformEmbeddedFileWriterAIX : public PlatformEmbeddedFileWriterBase {
void DeclareLabel(const char* name) override;
void SourceInfo(int fileid, const char* filename, int line) override;
void DeclareFunctionBegin(const char* name) override;
void DeclareFunctionBegin(const char* name, uint32_t size) override;
void DeclareFunctionEnd(const char* name) override;
int HexLiteral(uint64_t value) override;
......
......@@ -63,7 +63,7 @@ class PlatformEmbeddedFileWriterBase {
virtual void DeclareLabel(const char* name) = 0;
virtual void SourceInfo(int fileid, const char* filename, int line) = 0;
virtual void DeclareFunctionBegin(const char* name) = 0;
virtual void DeclareFunctionBegin(const char* name, uint32_t size) = 0;
virtual void DeclareFunctionEnd(const char* name) = 0;
// Returns the number of printed characters.
......
......@@ -95,7 +95,8 @@ void PlatformEmbeddedFileWriterGeneric::SourceInfo(int fileid,
fprintf(fp_, ".loc %d %d\n", fileid, line);
}
void PlatformEmbeddedFileWriterGeneric::DeclareFunctionBegin(const char* name) {
void PlatformEmbeddedFileWriterGeneric::DeclareFunctionBegin(const char* name,
uint32_t size) {
DeclareLabel(name);
if (target_arch_ == EmbeddedTargetArch::kArm ||
......@@ -108,6 +109,7 @@ void PlatformEmbeddedFileWriterGeneric::DeclareFunctionBegin(const char* name) {
// to create a DWARF subprogram entry.
fprintf(fp_, ".type %s, @function\n", name);
}
fprintf(fp_, ".size %s, %u\n", name, size);
}
void PlatformEmbeddedFileWriterGeneric::DeclareFunctionEnd(const char* name) {}
......
......@@ -36,7 +36,7 @@ class PlatformEmbeddedFileWriterGeneric
void DeclareLabel(const char* name) override;
void SourceInfo(int fileid, const char* filename, int line) override;
void DeclareFunctionBegin(const char* name) override;
void DeclareFunctionBegin(const char* name, uint32_t size) override;
void DeclareFunctionEnd(const char* name) override;
int HexLiteral(uint64_t value) override;
......
......@@ -78,7 +78,9 @@ void PlatformEmbeddedFileWriterMac::SourceInfo(int fileid, const char* filename,
fprintf(fp_, ".loc %d %d\n", fileid, line);
}
void PlatformEmbeddedFileWriterMac::DeclareFunctionBegin(const char* name) {
// TODO(mmarchini): investigate emitting size annotations for OS X
void PlatformEmbeddedFileWriterMac::DeclareFunctionBegin(const char* name,
uint32_t size) {
DeclareLabel(name);
// TODO(mvstanton): Investigate the proper incantations to mark the label as
......
......@@ -34,7 +34,7 @@ class PlatformEmbeddedFileWriterMac : public PlatformEmbeddedFileWriterBase {
void DeclareLabel(const char* name) override;
void SourceInfo(int fileid, const char* filename, int line) override;
void DeclareFunctionBegin(const char* name) override;
void DeclareFunctionBegin(const char* name, uint32_t size) override;
void DeclareFunctionEnd(const char* name) override;
int HexLiteral(uint64_t value) override;
......
......@@ -418,7 +418,9 @@ void PlatformEmbeddedFileWriterWin::SourceInfo(int fileid, const char* filename,
// Its syntax is #line <line> "<filename>"
}
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name) {
// TODO(mmarchini): investigate emitting size annotations for Windows
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name,
uint32_t size) {
fprintf(fp_, "%s%s PROC\n", SYMBOL_PREFIX, name);
}
......@@ -522,7 +524,9 @@ void PlatformEmbeddedFileWriterWin::SourceInfo(int fileid, const char* filename,
// Its syntax is #line <line> "<filename>"
}
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name) {
// TODO(mmarchini): investigate emitting size annotations for Windows
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name,
uint32_t size) {
fprintf(fp_, "%s%s FUNCTION\n", SYMBOL_PREFIX, name);
}
......@@ -638,7 +642,9 @@ void PlatformEmbeddedFileWriterWin::SourceInfo(int fileid, const char* filename,
// Windows.
}
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name) {
// TODO(mmarchini): investigate emitting size annotations for Windows
void PlatformEmbeddedFileWriterWin::DeclareFunctionBegin(const char* name,
uint32_t size) {
DeclareLabel(name);
if (target_arch_ == EmbeddedTargetArch::kArm64) {
......
......@@ -33,7 +33,7 @@ class PlatformEmbeddedFileWriterWin : public PlatformEmbeddedFileWriterBase {
void DeclareLabel(const char* name) override;
void SourceInfo(int fileid, const char* filename, int line) override;
void DeclareFunctionBegin(const char* name) override;
void DeclareFunctionBegin(const char* name, uint32_t size) override;
void DeclareFunctionEnd(const char* name) override;
int HexLiteral(uint64_t value) override;
......
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