[sw] Fix embedded linking not including .crt or .vectors.
Fixes #1058.
Signed-off-by: Miguel Young de la Sota <mcyoung@google.com>
diff --git a/ci/run_verilator_pytest.sh b/ci/run_verilator_pytest.sh
index 018fe0e..0f2da6a 100755
--- a/ci/run_verilator_pytest.sh
+++ b/ci/run_verilator_pytest.sh
@@ -16,18 +16,16 @@
TEST_TARGETS=(
"tests/flash_ctrl/flash_test.vmem"
- # TODO: Temporarially disabled, since these tests are failing at HEAD.
- # See #1058.
- #"tests/hmac/sha256_test.vmem"
- #"tests/rv_timer/rv_timer_test.vmem"
+ "tests/hmac/sha256_test.vmem"
+ "tests/rv_timer/rv_timer_test.vmem"
)
if [[ ! -z ${MAKE_BUILD+x} ]]; then
BOOT_ROM_TARGET="sw/device/sim/boot_rom/rom.vmem"
TEST_TARGETS=(
"sw/device/sim/tests/flash_ctrl/sw.vmem"
- #"sw/device/sim/tests/hmac/sw.vmem"
- #"sw/device/sim/tests/rv_timer/sw.vmem"
+ "sw/device/sim/tests/hmac/sw.vmem"
+ "sw/device/sim/tests/rv_timer/sw.vmem"
)
fi
diff --git a/sw/device/exts/common/empty.c b/sw/device/exts/common/empty.c
new file mode 100644
index 0000000..c6af3f1
--- /dev/null
+++ b/sw/device/exts/common/empty.c
@@ -0,0 +1,8 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+/**
+ * This file serves no purpose other than to ensure that Meson treats otherwise
+ * empty static libraries as cross-compiled C.
+ */
diff --git a/sw/device/exts/common/meson.build b/sw/device/exts/common/meson.build
index f91214d..db75aa1 100644
--- a/sw/device/exts/common/meson.build
+++ b/sw/device/exts/common/meson.build
@@ -13,11 +13,25 @@
# RISC-V startup library. Every RISC-V executable should depend on this target.
riscv_crt = declare_dependency(
link_args: riscv_linker_args,
+ # This is included as a source, not as a static library, so that the .crt
+ # section is picked up correctly.
+ sources: ['_crt.c'],
+ dependencies: [sw_lib_irq],
+ # This argument exists solely so that Meson realizes that riscv_linker_script
+ # is part of the dependency graph. This seems to be the only way to convince
+ # Meson to behave in this way, for the following reasons:
+ # - The dependencies arg can only include artifacts from declare_dependency().
+ # - We can't put linker scripts into the sources list, since Meson has no
+ # clue how to deal with them.
+ # - custom_target() doesn't help, because we can't convince Meson to depend on
+ # a custom_target() unless it produces source files.
+ # - If we go with static_library, sources needs to be non-empty in order for
+ # Meson to correctly treat it as a cross-compile target (otherwise, we get
+ # linker errors). This is because Meson guesses the type of a target based
+ # off of the file extensions of the source files.
link_with: static_library(
- 'riscv_crt',
- sources: ['_crt.c'],
- # NOTE: This line is mostly to make sure that a change in link.ld causes a
- # recompilation.
+ 'riscv_linker_script_dep_shim',
+ sources: ['empty.c'],
link_depends: [riscv_linker_script],
- ),
+ )
)
diff --git a/sw/device/lib/meson.build b/sw/device/lib/meson.build
index ad4bc0c..44e6db7 100644
--- a/sw/device/lib/meson.build
+++ b/sw/device/lib/meson.build
@@ -82,11 +82,14 @@
# IRQ library (sw_lib_irq)
sw_lib_irq = declare_dependency(
+ # The IRQ handler definitions need to be included as a "source" rather than
+ # as part of a static library; this ensures that it is linked in as a .o
+ # file, so the .vectors section is picked up.
+ sources: ['irq_vectors.S'],
link_with: static_library(
'irq_ot',
sources: [
'handler.c',
- 'irq_vectors.S',
'irq.c'
],
dependencies: [
diff --git a/util/embedded_target.py b/util/embedded_target.py
index 280cbe6..6877717 100644
--- a/util/embedded_target.py
+++ b/util/embedded_target.py
@@ -18,7 +18,7 @@
filename = basename + '.dis'
output = os.path.join(outdir, filename)
f = open(output, "w")
- cmd = [objdump, '-SD', input, ]
+ cmd = [objdump, '-SDhl', input, ]
subprocess.run(cmd, stdout=f, check=True)
return output