Closed EngJay closed 6 days ago
I volunteer to address this - I think all that is needed is the addition of a conditional in the Ninja backend to change the order of the arguments when the compiler is TI C28x. And perhaps improving the naming or abstractions of the classes for the TI compilers and linkers.
I fiddled around enough to produce a correct minimal build but additional issues are found when attempting to modify generate_dynamic_link_rules()
and generate_link()
to order the args correctly for TI C28x. After the args are added in the correct order, a new problem is caused by the static lib args since they are no longer last and come before the input files.
The TI compiler requires linked static libs to be absolutely last, after the input object files, and also requires the full library name, so -llibc.a
or --library=libc.a
, but the existing methods in Meson produce -lc
when adding the dependency the proper Meson way and add it to the end of the linker args, which causes an error and undefined symbols.
What the TI compiler expects is libraries that end in .lib
to be included in the list of input object files and static libs ending in .a
to be included at the very end after the input object files.
What a correct Ninja linker rule looks like.
rule c_LINKER
command = cl2000 $ARGS -z --output_file=$out $LINK_ARGS $in $TI_C28X_STATIC_LIBS
description = Linking target $out
A TI C28 compiler-compliant command is then produced.
[1/1] cl2000 --c99 -O2 '--define=RELEASE -DNDEBUG' --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 --diag_suppress=10063 --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --define=F2837xD --define=CPU1 -v28 -ml -mt -z --output_file=src/example-i2c-ti-lp-f28379d-bme280.out /Users/ne10/embedded-hal-c/examples/ti/lp-f28379d/bme280/src/2837xD_RAM_lnk_cpu1.cmd /Users/ne10/embedded-hal-c/examples/ti/lp-f28379d/bme280/subprojects/c2000ware-core-sdk/driverlib/f2837xd/driverlib/ccs/Release/driverlib_eabi.lib -mmain.map --heap_size=0x200 --stack_size=0x3F8 --warn_sections -i/Applications/ti/ti-cgt-c2000_22.6.1.LTS/lib -i/Applications/ti/ti-cgt-c2000_22.6.1.LTS/include --reread_libs --define=RAM --diag_wrap=off --display_error_number --xml_link_info=example-i2c-ti-f28379d-bme280_linkInfo.xml --entry_point=code_start --rom_model src/example-i2c-ti-lp-f28379d-bme280.out.p/i2c_ex3_external_loopback.c.o src/example-i2c-ti-lp-f28379d-bme280.out.p/device_F2837xD_CodeStartBranch.asm.o src/example-i2c-ti-lp-f28379d-bme280.out.p/device_device.c.o -llibc.a
<Linking>
The TI C28x compilers have some really weird and specific requirements for how the commands have to be formatted that make trying to create them with the existing Meson implementation challenging but I think I have a way figured out with minimal changes. I'll open a PR once it's ironed out a little more.
A fix for most of this was merged as #13681 and is included in the 1.7 milestone. The remaining issues with TI support will be addressed as subsequent issues.
Describe the bug A clear and concise description of what the bug is.
There are three issues with the current support for TI code generation tools.
The compiler arguments are not included in the linker rule generated by the Ninja backend, so linking with the same arguments as compiling is impossible since the tools require that some of the options be included before the flag for linking,
-z
or--run_linker
. TI's C28x code gen tools are weird, so the requirements of the arguments are substantially different from the general implementation of the Ninja backend for generating linker rules.The order of
$in
and$LINK_ARGS
in the linker rule generated by the Ninja backend for the TI C28x code gen tools is out of order from the specification of the CLI of the tools, which causes problems with some arguments.The name of the TI code gen tools abstraction is imprecise because TI makes a wide variety of code gen tools with at least two different CLIs, only one of which is accommodated by the current implemetaton of the
TICompiler
andTIDynamicLinker
classes.Compiler arguments are not included when linking with TI C28x CGT
The TI C28x code gen tools require the compiler arguments to also be included when linking and they have to precede the flag that tells the tools to run the linker,
-z
or--run_linker
. The Ninja rule does include$ARGS
in the correct place but the variable is not populated. ~I have not been able to determine the cause of this, so I could use some help on it.~It appears that the
generate_link()
method on theNinjaBackend
does not addARGS
for any linking build rule, so a change would be needed there in order to include the compiler args in the correct place for the C28x CGT linker command.The generated ninja build file shows the line for ARGS is not included for the linking build rule.
Order of linker args is incorrect for TI C28x CGT
The TI C28x family (C2000, C6000, etc.) of code generation tools expect a precise order of arguments with which the linker commands generated by Meson do not conform. This causes problems when including certain arguments.
The Ninja backend generates the linker commands for these TI code generation tools with the arguments in an incorrect order.
An example of the Ninja linker rule generated with the order of the
$in
and$LINK_ARGS
reversed from the order specified by the TI CGT manuals.[builddir]/build.ninja
:The order of the arguments is specified in the TI docs for the compilers.
C2000-CGT specification from section 2.2 of the manual:
C6000-CGT specification from section 3.2 of the manual:
MSP430-CGT order of arguments for linking specification from section 2.2 of the manual.
This line in
generate_dynamic_link_rules()
inninjabackend.py
is the cause.I believe an exception is needed in this function in order to generate the linker command with the arguments in the correct order for the TI C28x and C29x code generation tools.
TI code gen tools abstraction is imprecise
The implementation of the support for TI compilers is imprecise because TI makes a wide variety of code generation tools that include the C28x variety that is the subject of this PR but also GCC for TI devices CGT that uses the familiar GCC order of arguments. Due to that, support for the TI GCC compiler could not be derived from the
TICompiler
class defined inti.py
since the CLI is different.To Reproduce Please include your
meson.build
files, preferably as a minimal toy example showing the issue. You may need to create simple source code files (don't include private/proprietary code).A minimal example has been created as a self-contained example repo that only requires Docker to run. See the repo's README for details.
c2000.txt
meson.build
Expected behavior A clear and concise description of what you expected to happen.
The expected behavior is to:
-z
argument in the generated linker command.-z
but before the output arguments.The expected Ninja rule for the TI C28x CGT.
[builddir]/build.ninja
:A minimal example of the expected command with the expected output.
system parameters
A cross build using a c2000.txt cross file with the current LTS version of the TI C28x C2000 Code Generation Tools.
Ubuntu 22.04 but in a Docker container running on macOS Ventura.
3.10.12
meson --version
1.5.1
ninja --version
if it's a Ninja build1.11.1.1