Commit Graph

76 Commits

Author SHA1 Message Date
Travis Geiselbrecht
be52909f49 [make][buildall] add ability to filter buildall by architecture
Clean up make targets list-arch and list-toolchain to be much faster and
work without needing to invoke the archtecture's arch rules.mk. This
should make it work on machines that do not have that particular
toolchain in the path.

This is setting up for using it in the github action script.
2025-07-18 21:51:50 -07:00
Travis Geiselbrecht
1a761abb83 [arch][arm] Add support for float/nofloat compile options
Was already added to arm64, but arch/arm hadn't picked up this feature
yet. Uncovered a few places here or there that wasn't marking code as
float/no-float, but this fixes a problem where newer compilers are
starting to sneak in vector code because they can.

Issue #406
2024-05-14 00:57:19 -07:00
Travis Geiselbrecht
5d8dd9c36a [make] add 'make tags'
Tries to generate a curated ctags file for the current project and
configuration.
2024-05-09 20:29:08 -07:00
Travis Geiselbrecht
6ed6f36fa0 [warnings] remove some redundant declarations
Discovered with -Wredundant-decls
2024-04-19 00:07:49 -07:00
Travis Geiselbrecht
f7b694e855 Revert "[clang][riscv] add -menable-experimental-extensions"
This reverts commit 37c3228443.

Decided it's probably not worth maintaining this and simply removed this
particular build combination (clang 13 + riscv) from the build matrix.
2024-04-08 00:08:01 -07:00
Travis Geiselbrecht
37c3228443 [clang][riscv] add -menable-experimental-extensions
When building with clang-13 the zba riscv extension triggers a build
failure unless this switch is set. Set it for now, though it appears to
not be necessary for clang 14 and above.

TODO: add a version check for clang for a series of switches set based
on version in engine.mk.
2024-04-07 23:34:37 -07:00
Matt Schulte
b0b2665cea [make] Add ability to deny modules from being used
Certain projects may want to prevent the usage of certain modules from
being used. Here are two examples of when this may occur:

1. The Project has it's own fdt library and does not want developer's
   using the version of libfdt included with LK

2. The project does not want developers using mincrypt.

`DENY_MODULES` is a list which developers can set in their own project
makefiles which is checked on each module inclusion. If that module is
on the deny list, it causes a build failure.
2023-12-04 00:53:01 -08:00
Travis Geiselbrecht
30dc320054 [github] Merge pull request #380 from arichardson/add-clang-ci
Allow building RISCV64 and x86_64 with clang and add a Clang CI job
2023-06-21 15:42:35 -07:00
Matt Schulte
9325ca7f3b Fix typo in endif comment 2023-06-21 15:36:22 -07:00
Alex Richardson
bf6ab93088 [riscv] Workaround for undef-weak symbol relocations with clang+lld
When building with clang -mcmodel=medany and linking with ld.lld, we get
out-of-range relocation errors for undefined __start_<section> symbols
since 0 cannot be represented as a PC-relative offset). This is not a
problem with ld.bfd since ld.bfd rewrites the instructions to avoid the
out-of-range PC-relative relocation. For now, the simplest workaround is
to build with -fpie -mcmodel=medany (thus indirecting these symbols via
the GOT). This will be done automatically once clang includes
https://reviews.llvm.org/D107280.

Without this change I get the following linker errors:
ld.lld: error: dev/driver.c:21:(.text+0x1E): relocation R_RISCV_PCREL_HI20 out of range: -524295 is not in [-524288, 524287]; references __start_devices

See https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/126 and
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/201.
2023-06-08 07:08:49 -07:00
Alex Richardson
69111c40f5 [make] Add a COMPILER_TYPE variable
This can be used to change compiler flags for GCC vs Clang.
2023-06-08 07:08:49 -07:00
Alex Richardson
135479c70e [riscv] Disable linker relaxations when linking with ld.lld
We have to compile RISC-V code with -mno-relax when linking with ld.lld
since ld.lld does not yet support RISC-V linker relaxations. Without this
change, linking with ld.lld results in many errors such as:
`relocation R_RISCV_ALIGN requires unimplemented linker relaxation`.

This support was implemented as part of LLVM 15, but to support older
versions of ld.lld we add the flag unconditionally for now.
2023-06-08 07:08:49 -07:00
Alex Richardson
8c20e005ca [make] Set LINKER_TYPE to lld when building with ld.lld
This will be needed in a follow-up commit to disable linker relaxations
for RISC-V since ld.ldd does not support them yet.
2023-06-08 07:08:49 -07:00
Alex Richardson
4a9d0c33bd [make] Build with -ffreestanding
We should build with -ffreestanding since we are building an OS kernel and
cannot rely on all hosted environment functionality being present.
Specifically this fixes a compilation error with clang caused by the
the #include_next <limits.h>:
```
In file included from target/pc-x86/config.c:9:
In file included from dev/include/dev/driver.h:10:
In file included from lib/libc/include/sys/types.h:10:
In file included from lib/libc/include/limits.h:5:
In file included from /usr/lib/llvm-15/lib/clang/15.0.7/include/limits.h:21:
/usr/include/limits.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
#include <bits/libc-header-start.h>
```
The flag fixes this issue by ensuring that __STDC_HOSTED__ is no longer set
to 1, so Clang's limits.h will not try to include the host system one.
2023-06-07 15:55:50 -07:00
Travis Geiselbrecht
c3a5c31aac [make][engine] make the setting of toolchain variables conditional
CC, LD, etc was already settable by the environment, but not by
local.mk, since they were assigned in engine.mk as :=. Change the set to
be conditional to fix this.
2023-06-01 17:53:22 -07:00
Alex Richardson
923541d4c2 [clang][arm64] Disable -Wasm-operand-widths warning
Clang incorrectly diagnoses msr operations as need a 64-bit operand even
if the underlying register is actually 32 bits. Silence this warning.
There are quite a few occurrences of this warning so I opted to add the
-Wno-flag instead of wrapping all callsites in
`#pragma clang diagnostic ignored -Wasm-operand-widths`.
2023-06-01 17:50:50 -07:00
Alex Richardson
231f58903b [make][clang] Do not add unsupported warning flags
Currently, clang does not support the -Wno-nonnull-compare and
-Wmaybe-uninitialized warning flags so this adds lots of unknown warning
flag output for each compile job when not using GCC.
This commit adds a makefile macro to check for supported warning flags
and only adds them if the compiler actually supports them.
2023-06-01 17:50:50 -07:00
Pedro Falcato
8ebbcea5ed [ubsan] Add UBSAN implementation
Add an UBSAN implementation and a new UBSAN switch to the make build.
The implementation is taken from Onyx and handles most of the cases
that should be needed for a kernel build. Floating point and fancy
C++ CFI features are not supported yet.

To build with UBSAN, pass UBSAN=1 to make such as:
PROJECT=pc-x86-64-test make -jN UBSAN=1
2023-02-18 16:47:16 -08:00
Travis Geiselbrecht
2367686854 [make] add a way for a module to opt into additional warnings
Move -Wmissing-declarations and -Wmissing-prototypes into this bucket.
Opt in most of the core top level modules in the system. More to follow.
2022-10-23 23:16:48 -07:00
Travis Geiselbrecht
3dff26ae7b [make] add BUILDDIR_SUFFIX build variable
This allows you to tag your build dirs with an optional string.

Update scripts/buildall to also allow building all release (DEBUG=0)
builds. Add a few other convenience switches.
2022-07-23 15:57:53 -07:00
Travis Geiselbrecht
cd96c43006 [make] define and undefine some make variables
Based on building with --warn-undefined-variables, find a few places in
the build system where undefined variables were used incorrectly, or
never set due to unused code.
2022-07-22 23:45:42 -07:00
Travis Geiselbrecht
6462cbf51c [arch][fpu] add ability to specify per file or module if code needs fpu
Have the arch define additional compiler flags to explicit support or
not support a floating point unit.

Add ability for modules to per file or for the whole module mark code
as needing floating point support.

Add default flags for arm64, riscv, and x86 toolchains.

Needed because gcc 12 is getting much more aggressive about using vector
instructions for non float code, so getting away with avoiding it was
no longer working.

Still not perfect: printf code is being compiled with float, so it's
possible to use floating point instructions inside core kernel or
interrupt handling code if a printf is used.

Possibly will have problems on architectures where mixing float and non
float code at the linker generates issues, but so far seems to be okay.
2022-07-17 16:32:24 -07:00
Travis Geiselbrecht
6edff96534 [make] update ip address to try to copy to in the 'install' target 2022-06-05 15:58:06 -07:00
Travis Geiselbrecht
1e88a6c354 [build] add commented out -Wmissing-declarations
This is a useful warning to have on, but keep it off for now since there
are a ton of warnings here, and probably in external projects that use
LK.

CLs incoming to fix the most egregious warning violations this uncovers.
2021-10-21 23:05:24 -07:00
Travis Geiselbrecht
ddd7cba04d [build] add a few pseudo targets to assist with building
list-arch and list-toolchain will compute and print the architecture and
toolchain needed to build the project the build is set to.

Used by the CI builder to decide what toolchain to grab.
2021-09-18 16:51:15 -07:00
Nick Bray
3f549a2e25 [make] Defer binding of EXTRA_BUILDDEPS to all::
Currently EXTRA_BUILDDEPS is evaluated before build.mk. This means that
userspace apps or other EXTRA_BUILDRULES cannot add items to
EXTRA_BUILDDEPS and have it function as would be expected.

Bug: 143636864
Change-Id: Idc1504b09f31b4c54148bb6892193d11f45e08ff
2021-04-08 23:55:27 -07:00
Travis Geiselbrecht
461ecbb677 [make][cpp] bump cpp revision to C++14
Shouldn't be a large problem, since it's been standard in gcc and clang
for quite a few years at this point.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
7b0ca3c984 [make] print debug level on build 2021-02-14 20:08:35 -08:00
Travis Geiselbrecht
1272d037aa [dev][virtio] remove some extraneous __PACKED attributes
From working with -Wpacked its clear that some of the virtio
structures are overly packed and result in bad codegen on particular
architectures such as riscv. Roll back from using packed but
statically assert that the sizes are correct for some future arch
where things naturally pack differently.
2020-07-25 20:04:21 -07:00
Travis Geiselbrecht
ba530722f5 [warning] add -Wdouble-promotion
Mostly just a few warnings where things are promoted via passing floats to
printf. Those we should generally remove anyway because they're just
benchmarking code. Most things LK runs on either doesn't have float or
doesn't have double sized floats.
2020-07-25 17:16:22 -07:00
Travis Geiselbrecht
f7d8e2300c [warnings] add -Wshadow which helps detect local variables that override globals
Nothing particularly bad showed up but cleaned up a bit of code.
2020-07-25 16:49:25 -07:00
Travis Geiselbrecht
5690a8bb58 [arch] make sure the arch rules file sets TOOLCHAIN_PREFIX, make sure riscv picks up the alt selector
ARCH_riscv*_TOOLCHAIN_PREFIX should override TOOLCHAIN_PREFIX like it does on some other arches.
While was at it clean up the rules.mk file a bit.
2020-07-12 13:41:11 -07:00
Travis Geiselbrecht
7d9f80974d [make][flags] remove -finline, which apparently does nothing
Been carrying this flag around for years but from sleuthing around in
the compiler it seems to only exist as the opposite to -fno-inline which
has an actual effect. Only reason -finline would do anything would be to
cancel a previous -fno-inline switch.
2020-05-16 18:54:44 -07:00
Travis Geiselbrecht
a634b338c5 [make] tweak the way top level modules are included and add a few comments
No functional change.
2019-07-13 15:56:08 -07:00
Travis Geiselbrecht
08a4ee17f0 [make] add build switch to set -Werror in compile steps 2018-12-16 16:54:31 -08:00
Travis Geiselbrecht
5d43aa25eb [arch][rules] create ARCH_LDFLAGS and clean up all the arch rules files to consistently use ARCH_* vars 2018-11-30 22:00:45 -08:00
Travis Geiselbrecht
5dea3e1933 [warnings] fix a few warnings introduced with newer version of gcc
Most of the warnings are new, such as needing to mark fallthroughs on
cases explicitly. A few are based on signed vs unsigned comparisons.

Disable one warning that was annoying about comparing null to arguments
marked nonnull.
2018-03-15 14:10:12 -07:00
Travis Geiselbrecht
1332d188cb [make][compiler] add -fno-common
This removes the COMMON section merging logic, which actually uncovered
a few duplicately declared symbols across compilation units.
2016-11-17 14:44:21 -08:00
Girts
3972b18697 [make] [lib/version] remove a misplaced .PHONY (#170)
When lib/version was included, a rule depended on .PHONY.  This would
unexpectedly invoke other rules defined as dependent on .PHONY (standard
phony-ness signal).

As a side effect, this used to generate srcfiles.txt and
include_paths.txt in build dir. Since they are useful, we might always
build those anyway, and not make them phony at all.
2016-10-07 11:24:29 -07:00
Girts Folkmanis
9a2fcf2b60 [make] don't call build engine multiple times.
If some included rule.mk defines an additional make target that the user
might want to call (e.g., "flash"), and user specifies a project name on
the command line, then previously the outer "makefile" would call
engine.mk multiple times. The new logic prevents that.

Additionally, silence extra "Nothing to be done" messages when calling
engine.mk again after removing the project name from make goals.
2016-09-30 10:41:23 -07:00
Travis Geiselbrecht
c3165fcd2a [make] explicitly set the C and C++ standards to C11 and C++11
Seems to be supported at least back to gcc 4.8.2, which is I think
a reasonable minimum version.
2016-02-21 13:40:23 -08:00
Travis Geiselbrecht
6b480fd051 [make] remove -fno-builtin 2016-02-07 16:05:46 -08:00
Travis Geiselbrecht
84709d49f5 [make] add a quick in dirty help target for the build system
make help: a quick overview of how to use the build system
make list: a list of all the buildable projects
2016-01-30 14:43:12 -08:00
Travis Geiselbrecht
0bea90f76c [make] add the ARCH_* compile options to config.h 2015-12-08 14:20:37 -08:00
Travis Geiselbrecht
8a57db12ee [make] output a text file with all the source files and include paths used in the build 2015-11-20 21:00:44 -08:00
Travis Geiselbrecht
0e1ce411ba [make] add ability to set EXTRA_LINKER_SCRIPTS in modules
This allows for individual modules to extend the main linker script,
primarily to add their own sections to interate over.
Remove the main shared_* linker scripts.
2015-10-26 16:47:18 -07:00
Travis Geiselbrecht
3cb52cdf3d [make] add -Werror=return-type
Why gcc just warns about no return statement in a function that is supposed
to return something, I dunno. Fix that glitch.
2015-08-31 12:16:49 -07:00
Michael Ryleev
42694e06e6 [make] Fixup dependencies for modules included by EXTRA_BUILDRULES
Move statement that sets DEPS make variable a bit later in engine.mk
execution flow (after including make/build.mk) so that it would include
modules added through EXTRA_BUILDRULES mechanism.

Change-Id: I5c7a02eaf272f009a81ac9868f378b9baa23faae
2015-08-24 15:47:29 -07:00
Arve Hjønnevåg
2c9c5959e7 Merge branch 'master' of https://github.com/travisg/lk into smp
Change-Id: Iecb11d57b6f089234c0826932bdb229588939750
2015-05-18 16:49:37 -07:00
Travis Geiselbrecht
9fcf5cffaa [make] add -Wno-unused-label to the global compile flags
This is almost always due to #ifdefed code referring to a label.
Since you cant mark a label as UNUSED the way you can a variable,
adding this warning squelch seems like the best strategy.
2015-05-02 22:48:57 -07:00