Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking fails on armv6l due to missing libatomic #5219

Closed
lopsided98 opened this issue Oct 2, 2018 · 9 comments · Fixed by #5227
Closed

Linking fails on armv6l due to missing libatomic #5219

lopsided98 opened this issue Oct 2, 2018 · 9 comments · Fixed by #5227
Assignees

Comments

@lopsided98
Copy link
Contributor

What version of protobuf and what language are you using?
Version: v3.6.1

What operating system (Linux, Windows, ...) and version?
Linux (NixOS)

What runtime / compiler are you using (e.g., python version or gcc version)
gcc 7.3.0

What did you do?
When I attempted to build protobuf for armv6l, I ran into the following linker error:

./.libs/libprotobuf.so: undefined reference to `__atomic_fetch_add_8'

On armv6l, protobuf needs to be linked to libatomic to provide this symbol. Manually adding -latomic to LDFLAGS fixes the issue.

@acozzette
Copy link
Member

@lopsided98 Do you want to send us a pull request with the fix?

@lopsided98
Copy link
Contributor Author

I actually don't know exactly where in the build system to fix this. Protobuf seems to use both bazel and autotools, so would I have to add it to both?

I used autotools to build it, so I just added the -latomic to LDFLAGS on the command line.

@acozzette
Copy link
Member

Updating just the autotools build sounds fine to me, though we are thinking about deprecating it in favor of CMake some time soon so you might want to keep that in mind. By the way, do you have any more details on why we have to explicitly link against libatomic? Is that just a quirk of NixOS or armv6l?

@lopsided98
Copy link
Contributor Author

I think protobuf uses atomic intrinsics (maybe indirectly though std::atomic) that gcc cannot generate directly on armv6l, and instead needs to use a helper function in libatomic to implement them. Other architectures have instructions to implement them without libatomic.

I think this became a problem when protobuf stopped using its own implementations of atomic operations (src/google/protobuf/stubs/atomicops_internals_*) and switched to using std::atomic between 3.5 and 3.6.

@acozzette
Copy link
Member

Ok, that makes sense. I wonder if it's harmless to always link explicitly against libatomic or if we need a way to do that only for certain platforms.

@lopsided98
Copy link
Contributor Author

See #5227.

@martinblech
Copy link

Looks like there's been a regression on this issue somewhere between v3.11.4 and v3.12.2. I'm getting the same link error compiling "@com_google_protobuf//:protoc" v3.12.2 on a Raspberry Pi. v3.11.4 compiles just fine.

@FGasper
Copy link

FGasper commented Aug 24, 2022

I know this is an old issue, but does anyone know why armv6l specifically requires -latomic, and other Raspberry Pi platforms don’t seem to need it?

@lopsided98
Copy link
Contributor Author

ARMv6 lacks byte and half-word and double word atomic instructions (LDREXB, LDREXH, LDREXD, STREXB, STREXH, STREXD), so they need to be implemented with libatomic instead. See: https://developer.arm.com/documentation/dht0008/a/ch01s02s01

These instructions were actually added to the ARMv6K architecture, which appears to be supported by the ARM1176JZF-S CPU used in the BCM2835, but the compiler is not configured to target this architecture version. See: https://developer.arm.com/documentation/ddi0301/h/summary-of-arm1136jf-s-and-arm1176jzf-s-processor-differences/summary-of-differences/armv6k-extensions-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants