[MSP430] Fix LD errors when linking LTO debug objects

Message ID 46bba2da-e430-b8fb-b407-da6312a32894@mittosystems.com
State Superseded
Headers show
Series
  • [MSP430] Fix LD errors when linking LTO debug objects
Related show

Commit Message

Jozef Lawrynowicz Oct. 31, 2018, 11:31 p.m.
When invoking GCC with "-g -flto", the compiler will create LTO objects with
debug information. The objects created are "simple ELF" objects (see
libiberty/simple-object-elf.c) and do not have target-specific sections.

When the MSP430 linker sees one of these objects without a 
.MSP430.attributes
section it errors:

error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses MSP430X instructions but 
/tmp/ccynqIwudebugobj uses unknown
error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small code model whereas 
/tmp/ccynqIwudebugobj uses the unknown code model
error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small data model whereas 
/tmp/ccynqIwudebugobj uses the unknown data model
error: /tmp/cc4LhbEI.ltrans0.ltrans.o uses the small code model but 
/tmp/ccynqIwudebugobj uses the unknown data model
failed to merge target specific data of file /tmp/cc4LhbEI.ltrans0.ltrans.o

The following patch allows these debug LTO objects to be linked with other
MSP430 objects even if they do not have a .MSP430.attributes section.

If the patch is acceptable, I would appreciate if someone would commit it
for me, as I don't have write access.

Patch

From 91a2fc8879e757ca4daa6ba32618c8ee88eebc16 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@mittosystems.com>
Date: Wed, 31 Oct 2018 22:29:25 +0000
Subject: [PATCH] [MSP430] Fix link failure when linking LTO debug objects

2018-10-31  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

bfd/ChangeLog

	* elf32-msp430.c (elf32_msp430_merge_mspabi_attributes): Do not error
	when .MSP430.attributes section is missing from objects created by LTO.

---
 bfd/elf32-msp430.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
index 2d351d3..95dae2e 100644
--- a/bfd/elf32-msp430.c
+++ b/bfd/elf32-msp430.c
@@ -2424,6 +2424,12 @@  elf32_msp430_merge_mspabi_attributes (bfd *ibfd, struct bfd_link_info *info)
   if (ibfd->flags & BFD_LINKER_CREATED)
     return TRUE;
 
+  /* LTO can create temporary files for linking which may not have an attribute
+     section.  */
+  if (ibfd->lto_output
+      && bfd_get_section_by_name (ibfd, ".MSP430.attributes") == NULL)
+    return TRUE;
+
   /* If this is the first real object just copy the attributes.  */
   if (!elf_known_obj_attributes_proc (obfd)[0].i)
     {
-- 
2.7.4