Skip to content

Commit 6d608fb

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[gen_snapshot] Provide option to generate ELF libraries pre-stripped.
Change-Id: I13631e21e114296a268aeeaad570b8613273af10 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105121 Commit-Queue: Siva Annamalai <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent 454758d commit 6d608fb

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

runtime/bin/gen_snapshot.cc

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,19 @@ static const char* kSnapshotKindNames[] = {
119119
V(reused_instructions, reused_instructions_filename) \
120120
V(blobs_container_filename, blobs_container_filename) \
121121
V(assembly, assembly_filename) \
122+
V(elf, elf_filename) \
122123
V(load_compilation_trace, load_compilation_trace_filename) \
123124
V(load_type_feedback, load_type_feedback_filename) \
124125
V(save_obfuscation_map, obfuscation_map_filename)
125126

126127
#define BOOL_OPTIONS_LIST(V) \
127-
V(read_all_bytecode, read_all_bytecode) \
128128
V(compile_all, compile_all) \
129+
V(help, help) \
129130
V(obfuscate, obfuscate) \
131+
V(read_all_bytecode, read_all_bytecode) \
132+
V(strip, strip) \
130133
V(verbose, verbose) \
131-
V(version, version) \
132-
V(help, help)
134+
V(version, version)
133135

134136
#define STRING_OPTION_DEFINITION(flag, variable) \
135137
static const char* variable = NULL; \
@@ -188,6 +190,14 @@ static void PrintUsage() {
188190
"[--save-obfuscation-map=<map-filename>] \n"
189191
"<dart-kernel-file> \n"
190192
" \n"
193+
"To create an AOT application snapshot as an ELF shared library: \n"
194+
"--snapshot_kind=app-aot-elf \n"
195+
"--elf=<output-file> \n"
196+
"[--strip] \n"
197+
"[--obfuscate] \n"
198+
"[--save-obfuscation-map=<map-filename>] \n"
199+
"<dart-kernel-file> \n"
200+
" \n"
191201
"AOT snapshots can be obfuscated: that is all identifiers will be renamed \n"
192202
"during compilation. This mode is enabled with --obfuscate flag. Mapping \n"
193203
"between original and obfuscated names can be serialized as a JSON array \n"
@@ -317,16 +327,16 @@ static int ParseArguments(int argc,
317327
}
318328
break;
319329
}
320-
case kAppAOTAssembly:
321330
case kAppAOTElf: {
322-
if (assembly_filename == NULL) {
331+
if (elf_filename == NULL) {
323332
Syslog::PrintErr(
324333
"Building an AOT snapshot as assembly requires specifying "
325-
"an output file for --assembly.\n\n");
334+
"an output file for --elf.\n\n");
326335
return -1;
327336
}
328337
break;
329338
}
339+
case kAppAOTAssembly:
330340
case kVMAOTAssembly: {
331341
if (assembly_filename == NULL) {
332342
Syslog::PrintErr(
@@ -630,9 +640,15 @@ static void CreateAndWritePrecompiledSnapshot() {
630640
result = Dart_CreateAppAOTSnapshotAsAssembly(StreamingWriteCallback, file);
631641
CHECK_RESULT(result);
632642
} else if (snapshot_kind == kAppAOTElf) {
633-
File* file = OpenFile(assembly_filename);
643+
if (strip) {
644+
Syslog::PrintErr(
645+
"Warning: Generating ELF library without DWARF debugging"
646+
" information.\n");
647+
}
648+
File* file = OpenFile(elf_filename);
634649
RefCntReleaseScope<File> rs(file);
635-
result = Dart_CreateAppAOTSnapshotAsElf(StreamingWriteCallback, file);
650+
result =
651+
Dart_CreateAppAOTSnapshotAsElf(StreamingWriteCallback, file, strip);
636652
CHECK_RESULT(result);
637653
} else if (snapshot_kind == kAppAOTBlobs) {
638654
const uint8_t* shared_data = NULL;

runtime/include/dart_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,8 @@ Dart_CreateAppAOTSnapshotAsAssembly(Dart_StreamingWriteCallback callback,
33063306
*/
33073307
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
33083308
Dart_CreateAppAOTSnapshotAsElf(Dart_StreamingWriteCallback callback,
3309-
void* callback_data);
3309+
void* callback_data,
3310+
bool stripped);
33103311

33113312
/**
33123313
* Like Dart_CreateAppAOTSnapshotAsAssembly, but only includes

runtime/vm/dart_api_impl.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6065,7 +6065,8 @@ Dart_CreateVMAOTSnapshotAsAssembly(Dart_StreamingWriteCallback callback,
60656065

60666066
DART_EXPORT Dart_Handle
60676067
Dart_CreateAppAOTSnapshotAsElf(Dart_StreamingWriteCallback callback,
6068-
void* callback_data) {
6068+
void* callback_data,
6069+
bool strip) {
60696070
#if defined(TARGET_ARCH_IA32)
60706071
return Api::NewError("AOT compilation is not supported on IA32.");
60716072
#elif defined(TARGET_ARCH_DBC)
@@ -6089,8 +6090,12 @@ Dart_CreateAppAOTSnapshotAsElf(Dart_StreamingWriteCallback callback,
60896090
NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(),
60906091
"WriteAppAOTSnapshot"));
60916092
StreamingWriteStream elf_stream(2 * MB, callback, callback_data);
6093+
60926094
Elf* elf = new (Z) Elf(Z, &elf_stream);
6093-
Dwarf* dwarf = new (Z) Dwarf(Z, nullptr, elf);
6095+
Dwarf* dwarf = nullptr;
6096+
if (!strip) {
6097+
dwarf = new (Z) Dwarf(Z, nullptr, elf);
6098+
}
60946099

60956100
BlobImageWriter vm_image_writer(T, &vm_snapshot_instructions_buffer,
60966101
ApiReallocate, /* initial_size= */ 2 * MB,
@@ -6108,9 +6113,11 @@ Dart_CreateAppAOTSnapshotAsElf(Dart_StreamingWriteCallback callback,
61086113
writer.VmIsolateSnapshotSize());
61096114
elf->AddROData("_kDartIsolateSnapshotData", isolate_snapshot_data_buffer,
61106115
writer.IsolateSnapshotSize());
6111-
// TODO(rmacnak): Generate .debug_frame / .eh_frame / .arm.exidx to
6112-
// providing unwinding information.
6113-
dwarf->Write();
6116+
if (!strip) {
6117+
// TODO(rmacnak): Generate .debug_frame / .eh_frame / .arm.exidx to
6118+
// provide unwinding information.
6119+
dwarf->Write();
6120+
}
61146121
elf->Finalize();
61156122

61166123
return Api::Success();

runtime/vm/image_snapshot.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void AssemblyImageWriter::WriteText(WriteStream* clustered_stream, bool vm) {
540540

541541
#ifdef DART_PRECOMPILER
542542
// Create a label for use by DWARF.
543-
if (!code.IsNull()) {
543+
if ((dwarf_ != nullptr) && !code.IsNull()) {
544544
const intptr_t dwarf_index = dwarf_->AddCode(code);
545545
assembly_stream_.Print(".Lcode%" Pd ":\n", dwarf_index);
546546
}
@@ -751,7 +751,7 @@ void BlobImageWriter::WriteText(WriteStream* clustered_stream, bool vm) {
751751

752752
#ifdef DART_PRECOMPILER
753753
const Code& code = *instructions_[i].code_;
754-
if ((elf_ != nullptr) && !code.IsNull()) {
754+
if ((elf_ != nullptr) && (dwarf_ != nullptr) && !code.IsNull()) {
755755
intptr_t segment_offset = instructions_blob_stream_.bytes_written() +
756756
Instructions::HeaderSize();
757757
dwarf_->AddCode(code, segment_base + segment_offset);

tools/testing/dart/compiler_configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
752752
args.add("--blobs_container_filename=$tempDir/out.aotsnapshot");
753753
} else if (_configuration.useElf) {
754754
args.add("--snapshot-kind=app-aot-elf");
755-
args.add("--assembly=$tempDir/out.aotsnapshot");
755+
args.add("--elf=$tempDir/out.aotsnapshot");
756756
} else {
757757
args.add("--snapshot-kind=app-aot-assembly");
758758
args.add("--assembly=$tempDir/out.S");

0 commit comments

Comments
 (0)