On 02/12/2018 03:23 AM, Andreas Schwab wrote:
On Feb 06 2017, Palmer Dabbelt <pal...@dabbelt.com> wrote:

+/* Because RISC-V only has word-sized atomics, it requries libatomic where
+   others do not.  So link libatomic by default, as needed.  */
+#undef LIB_SPEC
+#ifdef LD_AS_NEEDED_OPTION
+#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC \
+  " %{pthread:" LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION "}"
+#else
+#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC " -latomic "
+#endif

Why is -latomic added only with -pthread if --as-needed is supported,
but unconditionally if not?  Wouldn't it make sense to add it
unconditionally in both cases?

I don't know the history here, but I do know that the most common atomic related bug report we get is for people using pthread, so we were probably thinking about that when this was written. But handling the two cases differently does look like a bug. I'm OK with a patch that makes it unconditional in the LD_AS_NEEDED_OPTION case also. Particularly if you have a good case to justify it. Joseph's pointer to bug 81358 looks like a possible good justification for this. Do you want to write a patch, or do you want me to write it?

I'm not worried about the case where --as-needed is missing. Linker --as-needed support was added to GNU ld in 2004, and RISC-V support was added to GCC in 2017, so there should be no riscv target that is missing the linker --as-needed support.

Jim

Reply via email to