This is an archive of the discontinued LLVM Phabricator instance.

Fix ARM bare metal driver to support atomics
ClosedPublic

Authored by itessier on Sep 5 2017, 2:38 PM.

Details

Summary

The new bare metal support only supports the single thread model. This causes the builtin atomic functions (e.g.: __atomic_fetch_add) to not generate thread-safe assembly for these operations, which breaks our firmware. We target bare metal, and need to atomically modify variables in our interrupt routines, and task threads.

Internally, the -mthread-model flag determines whether to lower or expand atomic operations (see D4984).

This change removes the overridden thread model methods, and instead relies on the base ToolChain class to validate the thread model (which already includes logic to validate single thread model support). If the single thread model is required, the -mthread-model flag will have to be provided.

As a workaround "-mthread-model posix" could be provided, but it only works due to a bug in the validation of the -mthread-model flag (separate patch coming to fix this).

Diff Detail

Event Timeline

itessier created this revision.Sep 5 2017, 2:38 PM

I think this is wrong. "arm-none-eabi" covers RTOS threads too, where you really should use ldrex/strex loops unless you have good reason; and even kernels can be interrupted if they decide they want it.

IMO, -mthread-model=single is how this should be specified (except on baseline M-class where those instructions don't exist; there we may have a bug, though I've not checked). And the default should be safe.

t.p.northover accepted this revision.Sep 5 2017, 2:49 PM

Oh hang on, I see you're undoing something which broke my assumptions. In which case, I completely agree with everything.

This revision is now accepted and ready to land.Sep 5 2017, 2:49 PM
jroelofs edited edge metadata.Sep 5 2017, 2:56 PM

FWIW, I defaulted this to -mthread-model=single to match existing baremetal gcc toolchains, and support armv4t & others that don't have the requisite atomic ops.

I don't have SVN access, can somebody commit this change for me?

Sure. I'll commit it for you once this build/test cycle is finished.

jroelofs closed this revision.Sep 6 2017, 10:10 AM

r312651