Skip to content

Commit cd6d40e

Browse files
committed
Use a linker script
1 parent 49eee8e commit cd6d40e

6 files changed

Lines changed: 81 additions & 9 deletions

File tree

kmake/Data/kompjuta/kompjuta.ld

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ENTRY(_start)
2+
3+
MEMORY {
4+
RAM (rwx) : ORIGIN = 0x00010000, LENGTH = 256M
5+
}
6+
7+
SECTIONS {
8+
.text : ALIGN(16) {
9+
KEEP(*(.text.start))
10+
*(.text*)
11+
*(.rodata*)
12+
} > RAM
13+
14+
.eh_frame : { *(.eh_frame*) } > RAM
15+
16+
.data : ALIGN(16) {
17+
__data_start = .;
18+
*(.data*)
19+
__data_end = .;
20+
} > RAM
21+
22+
.bss (NOLOAD) : ALIGN(16) {
23+
__bss_start = .;
24+
*(.bss*)
25+
*(COMMON)
26+
__bss_end = .;
27+
} > RAM
28+
29+
. = ALIGN(16);
30+
__heap_base = .;
31+
__heap_end = ORIGIN(RAM) + LENGTH(RAM) - 1M;
32+
33+
__stack_bottom = __heap_end;
34+
__stack_top = __heap_end + 1M;
35+
}

kmake/src/Exporters/KompjutaExporter.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { NinjaExporter } from 'kmake/Exporters/NinjaExporter';
44
import { MakeExporter } from 'kmake/Exporters/MakeExporter';
55
import { CLionExporter } from 'kmake/Exporters/CLionExporter';
66
import { CompilerCommandsExporter } from 'kmake/Exporters/CompileCommandsExporter';
7+
import * as fs from 'kmake/fsextra';
8+
import * as path from 'path';
79

810
export class KompjutaExporter extends Exporter {
911
ninja: NinjaExporter;
@@ -14,17 +16,23 @@ export class KompjutaExporter extends Exporter {
1416
constructor(options: any) {
1517
super(options);
1618

17-
let flags = '--target=riscv64-unknown-elf -march=rv64imfd -mabi=lp64d -Os -ffreestanding -fno-builtin -nostdlib -nostartfiles -mno-relax "-Wl,--no-relax"';
19+
const cFlags = '--target=riscv64-unknown-elf -march=rv64imfd -mabi=lp64d -Os -ffreestanding -fno-builtin -ffunction-sections -fdata-sections -nostdlib -mno-relax';
20+
const linkerFlags = '--target=riscv64-unknown-elf -march=rv64imfd -mabi=lp64d -Os -ffreestanding -fno-builtin -ffunction-sections -fdata-sections -nostdlib -mno-relax "-Wl,--no-relax,--gc-sections,-Map,link.map,-T,kompjuta.ld"';
1821

19-
let outputExtension = '.elf';
22+
const outputExtension = '.elf';
2023

21-
this.ninja = new NinjaExporter(options, 'clang', 'clang++', flags, flags, flags, outputExtension);
22-
this.make = new MakeExporter(options, 'clang', 'clang++', flags, flags, flags, outputExtension);
24+
this.ninja = new NinjaExporter(options, 'clang', 'clang++', cFlags, cFlags, linkerFlags, outputExtension);
25+
this.make = new MakeExporter(options, 'clang', 'clang++', cFlags, cFlags, linkerFlags, outputExtension);
2326
this.clion = new CLionExporter(options);
2427
this.compileCommands = new CompilerCommandsExporter(options);
2528
}
2629

2730
async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
31+
const textData = require('fs').getEmbeddedData();
32+
let outputPath = path.resolve(to, options.buildPath);
33+
fs.ensureDirSync(outputPath);
34+
fs.writeFileSync(path.join(outputPath, 'kompjuta.ld'), textData['kompjuta_kompjuta_ld']);
35+
2836
this.ninja.exportSolution(project, from, to, platform, vrApi, options);
2937
this.make.exportSolution(project, from, to, platform, vrApi, options);
3038
this.clion.exportSolution(project, from, to, platform, vrApi, options);

lib/kmake/Exporters/KompjutaExporter.js

Lines changed: 11 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/kmake/Exporters/KompjutaExporter.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node.gyp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,24 @@
14471447
'<@(_outputs)',
14481448
],
14491449
},
1450+
{
1451+
'action_name': 'kompjuta_kompjuta_ld',
1452+
'process_outputs_as_sources': 1,
1453+
'inputs': [
1454+
'tools/text_to_header.py',
1455+
'kmake/Data/kompjuta/kompjuta.ld'
1456+
],
1457+
'outputs': [
1458+
'<(SHARED_INTERMEDIATE_DIR)/kompjuta_kompjuta_ld.h',
1459+
],
1460+
'action': [
1461+
'<(python)',
1462+
'tools/text_to_header.py',
1463+
'kompjuta_kompjuta_ld',
1464+
'kmake/Data/kompjuta/kompjuta.ld',
1465+
'<@(_outputs)',
1466+
],
1467+
},
14501468
],
14511469
}, # node_lib_target_name
14521470
{ # fuzz_env

src/node_file.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
#include "android_main_androidmanifest_xml.h"
7474
#include "android_main_res_values_strings_xml.h"
7575

76+
#include "kompjuta_kompjuta_ld.h"
77+
7678
#if defined(__MINGW32__) || defined(_MSC_VER)
7779
# include <io.h>
7880
#endif
@@ -3833,6 +3835,8 @@ static void GetEmbeddedData(const FunctionCallbackInfo<Value>& args) {
38333835
data->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "android_main_androidmanifest_xml"), FIXED_ONE_BYTE_STRING(isolate, android_main_androidmanifest_xml)).Check();
38343836
data->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "android_main_res_values_strings_xml"), FIXED_ONE_BYTE_STRING(isolate, android_main_res_values_strings_xml)).Check();
38353837

3838+
data->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "kompjuta_kompjuta_ld"), FIXED_ONE_BYTE_STRING(isolate, komjuta_kompjuta_ld)).Check();
3839+
38363840
args.GetReturnValue().Set(data);
38373841
}
38383842

0 commit comments

Comments
 (0)