Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

LLVM error on High Sierra #74

Closed
fmckeogh opened this issue May 16, 2018 · 13 comments
Closed

LLVM error on High Sierra #74

fmckeogh opened this issue May 16, 2018 · 13 comments

Comments

@fmckeogh
Copy link

fmckeogh commented May 16, 2018

Building cortex-m-rt on nightly, beta and stable in Mac OS High Sierra (tested on two machines) results in the following error:

LLVM ERROR: Global variable '__RESET_VECTOR' has an invalid section specifier '.vector_table.reset_vector': mach-o section specifier requires a segment whose length is between 1 and 16 characters.

It build correctly on my Ubuntu 18.04 machine.

@japaric
Copy link
Member

japaric commented May 16, 2018

mach-o section specifier requires a segment whose length is between 1 and 16 characters

Are you compiling the cortex-m-rt crate for the host (for mac)?

If that's the case we can drop the link_section when compiling for mac; trying to link a cortex-m program compiled for the host (mac / Linux) is going to fail anyway.

@fmckeogh
Copy link
Author

fmckeogh commented May 16, 2018

I'm so sorry for wasting your time, I'm the biggest idiot. I forgot to set the default target in .cargo/config.

@jonas-schievink
Copy link
Contributor

The cortex-m crate goes out of its way to build at least on Linux, would be nice if all the core crates consistently built on Linux, macOS, and Windows

@japaric
Copy link
Member

japaric commented Jan 15, 2021

we ran into a similar issue in the defmt project.
we found out that on macOS the longest linker section name can be .section,0123456789ABCDEF (note: comma after .section not period and a max of 16 characters after the comma)
this issue can probably be fixed by adding a cfg_attr(is_macos, link_section = "..") to the relevant static variables

@therealprof
Copy link
Contributor

Indeed, I've encountered it frequently.

bors bot added a commit that referenced this issue Jan 26, 2021
306: fix #74 r=jonas-schievink a=spookyvision

special-cased linker section names to satisfy macos linker constraints

Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
@bors bors bot closed this as completed in 4bbee87 Jan 26, 2021
@berkus
Copy link
Member

berkus commented Jan 27, 2021

What does this fix do? It replaces section name with exactly the same but taking half a kilobyte more space in source code; am I missing something there?

@therealprof
Copy link
Contributor

@berkus Not sure what you mean. What are you seeing and on which system? This is changing the section names for macOS only because it has a weird length restriction. It should not affect anything except to prevent linker errors on macOS.

@berkus
Copy link
Member

berkus commented Jan 27, 2021

@therealprof ok, lets go with the way of example, shall we.

#[cfg_attr(target_os = "macos", link_section = ".vector_table,interrupts")]
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.interrupts")]

On macOS the section name would be .vector_table.interrupts, however on any other system it would be .vector_table.interrupts which is EXACTLY THE SAME.

So now you've reduced readability, understandability and maintainability of the code to provide exactly the same section names for every system out there.

What am I missing? I could have missed something, to be precise am looking at this commit.

Here it is, condensed:

#[cfg_attr(target_os = "macos", link_section = ".HardFault,user")]
#[cfg_attr(not(target_os = "macos"), link_section = ".HardFault.user")] // NB: same name

#[cfg_attr(target_os = "macos", link_section = ".vector_table,reset_vector")]
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.reset_vector")] // NB: same name

#[cfg_attr(target_os = "macos", link_section = ".HardFault,default")]
#[cfg_attr(not(target_os = "macos"), link_section = ".HardFault.default")] // NB: same name

#[cfg_attr(target_os = "macos", link_section = ".vector_table,exceptions")]
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.exceptions")] // NB: same name

#[cfg_attr(target_os = "macos", link_section = ".vector_table,interrupts")]
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.interrupts")] // NB: same name

@berkus
Copy link
Member

berkus commented Jan 27, 2021

Ahha, now I see the comma vs period, my bad!

@berkus
Copy link
Member

berkus commented Jan 27, 2021

@therealprof btw, could it be using the comma on all systems, not only macos?

@therealprof
Copy link
Contributor

Not sure sorry, I'm actually curious why this is supposed to work on macOS (NB: I haven't actually tested it myself). Maybe some internal linker magic to substitute the "." back?

@berkus
Copy link
Member

berkus commented Jan 27, 2021

@therealprof on mac this is two names, ".vector_table" for the segment and "reset_vector" for the section name.

I will test on linux if a section name with comma works, the ELF file format spec says why not so the only limiting factor would be linker's parser.

@adamgreig
Copy link
Member

We could probably just remove the link_section attribute entirely on MacOS, right? It's not going to actually do anything as I understand it, since we can't build final libraries or executables targeting MacOS with cortex-m-rt and it doesn't use our linker script (where the names matter) on MacOS either; this change just lets people on MacOS run cargo check/test without a target specified. I wouldn't want to swap the ARM builds or linker script to using commas for section names just so that Macs can check the code when compiling natively, though.

bors bot added a commit that referenced this issue Jan 27, 2021
310: Only emit link_section for cortex-m r=jonas-schievink a=adamgreig

Previously we always emitted `link_section`, even though it only had an
effect when our linker script was being used (and only made sense on
cortex-m targets). This breaks building the code for a MacOS target,
which is occasionally useful for running `cargo check` etc.

In the macros crate we don't have the target information available, so
instead we continue to emit `link_section` except specifically on MacOS.

This keeps the fix from #306 but hopefully resolves the confusion in #74 (comment).

Co-authored-by: Adam Greig <adam@adamgreig.com>
adamgreig added a commit to rust-embedded/cortex-m that referenced this issue Jan 12, 2022
310: Only emit link_section for cortex-m r=jonas-schievink a=adamgreig

Previously we always emitted `link_section`, even though it only had an
effect when our linker script was being used (and only made sense on
cortex-m targets). This breaks building the code for a MacOS target,
which is occasionally useful for running `cargo check` etc.

In the macros crate we don't have the target information available, so
instead we continue to emit `link_section` except specifically on MacOS.

This keeps the fix from #306 but hopefully resolves the confusion in rust-embedded/cortex-m-rt#74 (comment).

Co-authored-by: Adam Greig <adam@adamgreig.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants