+#define is_nios2_elf(bfd) \
+ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+ && elf_object_id (bfd) == NIOS2_ELF_DATA)
+
+/* Merge backend specific data from an object file to the output
+ object file when linking. */
+
+static bfd_boolean
+nios2_elf32_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+{
+ flagword old_flags;
+ flagword new_flags;
+
+ if (!is_nios2_elf (ibfd) || !is_nios2_elf (obfd))
+ return TRUE;
+
+ /* Check if we have the same endianness. */
+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+ return FALSE;
+
+ new_flags = elf_elfheader (ibfd)->e_flags;
+ old_flags = elf_elfheader (obfd)->e_flags;
+ if (!elf_flags_init (obfd))
+ {
+ /* First call, no flags set. */
+ elf_flags_init (obfd) = TRUE;
+ elf_elfheader (obfd)->e_flags = new_flags;
+
+ switch (new_flags)
+ {
+ default:
+ case EF_NIOS2_ARCH_R1:
+ bfd_default_set_arch_mach (obfd, bfd_arch_nios2, bfd_mach_nios2r1);
+ break;
+ case EF_NIOS2_ARCH_R2:
+ if (bfd_big_endian (ibfd))
+ {
+ (*_bfd_error_handler)
+ (_("error: %B: Big-endian R2 is not supported."), ibfd);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ bfd_default_set_arch_mach (obfd, bfd_arch_nios2, bfd_mach_nios2r2);
+ break;
+ }
+ }
+
+ /* Incompatible flags. */
+ else if (new_flags != old_flags)
+ {
+ /* So far, the only incompatible flags denote incompatible
+ architectures. */
+ (*_bfd_error_handler)
+ (_("error: %B: Conflicting CPU architectures %d/%d"),
+ ibfd, new_flags, old_flags);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ /* Merge Tag_compatibility attributes and any common GNU ones. */
+ _bfd_elf_merge_object_attributes (ibfd, obfd);
+
+ return TRUE;
+}
+
+