Skip to content

Commit 8b4e085

Browse files
committed
feat: support arm constructors by requiring llvm arrays
adds a new plc_llvm crate that wraps llvm c++ apis. The only api currently provided is to expose the init array flag. This ensures that the constructors created by the compiler are actually called in aarch64 architectures.
1 parent 82cf1fa commit 8b4e085

File tree

58 files changed

+393
-643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+393
-643
lines changed

.github/workflows/linux.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ jobs:
2626
2727
test-linux:
2828
name: Test Linux
29-
runs-on: ubuntu-latest
29+
runs-on: ${{ matrix.config.os }}
30+
strategy:
31+
matrix:
32+
config:
33+
- { os: "ubuntu-latest" }
34+
- { os: "ubuntu-24.04-arm" }
3035
container: ghcr.io/plc-lang/rust-llvm:latest
3136
steps:
3237
- uses: actions/checkout@v3

.github/workflows/lit.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ on:
1212
jobs:
1313
lit-linux-debug:
1414
name: lit tests (Linux, debug build)
15-
runs-on: ubuntu-latest
15+
runs-on: ${{ matrix.config.os }}
16+
strategy:
17+
matrix:
18+
config:
19+
- { os: "ubuntu-latest" }
20+
- { os: "ubuntu-24.04-arm" }
1621
container: ghcr.io/plc-lang/rust-llvm:latest
1722
steps:
1823
- uses: actions/checkout@v3
@@ -32,4 +37,4 @@ jobs:
3237
- name: Run `build.sh --lit --release`
3338
shell: bash
3439
run: |
35-
./scripts/build.sh --lit --release
40+
./scripts/build.sh --lit --release

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ plc_util = { path = "./compiler/plc_util" }
2323
plc_diagnostics = { path = "./compiler/plc_diagnostics" }
2424
plc_index = { path = "./compiler/plc_index" }
2525
section_mangler = { path = "./compiler/section_mangler" }
26+
plc_llvm = { path = "./compiler/plc_llvm" }
2627
logos = "0.12.0"
2728
clap = { version = "3.0", features = ["derive"] }
2829
indexmap = "2.0"
@@ -31,6 +32,7 @@ regex = "1"
3132
shell-words = "1.1.0"
3233
plc_derive = { path = "./compiler/plc_derive" }
3334
lld_rs = { git = "https://github.com/mun-lang/lld-rs", rev = "3798ace" }
35+
3436
which = "4.2.5"
3537
log.workspace = true
3638
inkwell.workspace = true
@@ -79,6 +81,7 @@ members = [
7981
"compiler/plc_index",
8082
"compiler/section_mangler",
8183
"compiler/plc_lowering",
84+
"compiler/plc_llvm",
8285
"tests/test_utils",
8386
]
8487
default-members = [".", "compiler/plc_driver", "compiler/plc_xml"]

compiler/plc_driver/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ pub struct CompileParameters {
120120
name = "no-linker-script",
121121
long,
122122
global = true,
123-
group = "linker_script",
124123
help = "Specify that no linker script should be used"
125124
)]
125+
#[deprecated = "Does nothing"]
126126
pub no_linker_script: bool,
127127

128128
#[clap(

compiler/plc_driver/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ pub struct LinkOptions {
8888

8989
#[derive(Clone, Default, Debug)]
9090
pub enum LinkerScript {
91-
#[default]
91+
#[deprecated = "No longer used, the default build script is enough"]
9292
Builtin,
9393
Path(String),
94+
#[default]
9495
None,
9596
}
9697

compiler/plc_driver/src/pipelines.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use ast::{
1818
};
1919

2020
use itertools::Itertools;
21-
use log::debug;
2221
use participant::{PipelineParticipant, PipelineParticipantMut};
2322
use plc::{
2423
codegen::{CodegenContext, GeneratedModule},
@@ -51,7 +50,6 @@ use rayon::prelude::*;
5150
use source_code::{source_location::SourceLocation, SourceContainer};
5251

5352
use serde_json;
54-
use tempfile::NamedTempFile;
5553
use toml;
5654

5755
pub mod participant;
@@ -203,11 +201,7 @@ impl<T: SourceContainer> BuildPipeline<T> {
203201

204202
library_paths.extend_from_slice(self.project.get_library_paths());
205203
//Get the specified linker script or load the default linker script in a temp file
206-
let linker_script = if params.no_linker_script {
207-
LinkerScript::None
208-
} else {
209-
params.linker_script.clone().map(LinkerScript::Path).unwrap_or_default()
210-
};
204+
let linker_script = params.linker_script.clone().map(LinkerScript::Path).unwrap_or_default();
211205

212206
LinkOptions {
213207
libraries,
@@ -982,29 +976,11 @@ impl GeneratedProject {
982976
//HACK: Create a temp file that would contain the bultin linker script
983977
//FIXME: This has to be done regardless if the file is used or not because it has
984978
//to be in scope by the time we call the linker
985-
let mut file = NamedTempFile::new()?;
986979
match link_options.linker_script {
987-
LinkerScript::Builtin => {
988-
let target = self.target.get_target_triple().to_string();
989-
//Only do this on linux systems
990-
if target.contains("linux") {
991-
if target.contains("x86_64") {
992-
let content = include_str!("../../../scripts/linker/x86_64.script");
993-
writeln!(file, "{content}")?;
994-
linker.set_linker_script(file.get_location_str().to_string());
995-
} else if target.contains("aarch64") {
996-
let content = include_str!("../../../scripts/linker/aarch64.script");
997-
writeln!(file, "{content}")?;
998-
linker.set_linker_script(file.get_location_str().to_string());
999-
} else {
1000-
debug!("No script for target : {target}");
1001-
}
1002-
} else {
1003-
debug!("No script for target : {target}");
1004-
}
1005-
}
1006980
LinkerScript::Path(script) => linker.set_linker_script(script),
1007981
LinkerScript::None => {}
982+
#[allow(deprecated)]
983+
LinkerScript::Builtin => {}
1008984
};
1009985

1010986
match link_options.format {

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__external_files__external_file_function_call.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
2-
source: compiler/plc_driver/./src/tests/external_files.rs
2+
source: compiler/plc_driver/src/tests/external_files.rs
33
expression: "results.join(\"\\n\")"
4-
snapshot_kind: text
54
---
65
; ModuleID = 'main.st'
76
source_filename = "main.st"
@@ -31,7 +30,7 @@ source_filename = "__init___TestProject"
3130
target datalayout = "[filtered]"
3231
target triple = "[filtered]"
3332

34-
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___TestProject, i8* null }]
33+
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__init___TestProject, i8* null }]
3534

3635
define void @__init___TestProject() {
3736
entry:

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__external_files__external_file_global_var.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
2-
source: compiler/plc_driver/./src/tests/external_files.rs
2+
source: compiler/plc_driver/src/tests/external_files.rs
33
expression: "results.join(\"\\n\")"
4-
snapshot_kind: text
54
---
65
; ModuleID = 'main.st'
76
source_filename = "main.st"
@@ -39,7 +38,7 @@ source_filename = "__init___TestProject"
3938
target datalayout = "[filtered]"
4039
target triple = "[filtered]"
4140

42-
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___TestProject, i8* null }]
41+
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__init___TestProject, i8* null }]
4342

4443
define void @__init___TestProject() {
4544
entry:

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__multi_files__multiple_files_in_different_locations_with_debug_info.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ target triple = "[filtered]"
123123
%mainProg = type {}
124124

125125
@mainProg_instance = external global %mainProg
126-
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___TestProject, i8* null }]
126+
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__init___TestProject, i8* null }]
127127

128128
define void @__init___TestProject() {
129129
entry:

0 commit comments

Comments
 (0)