[v2,7/7] x86: GOT is an ELF-only entity

Message ID 6fec8fb8-3814-484a-a26e-7a15503af6c3@suse.com
State New
Headers
Series x86: further GOT{,PCREL} related adjustments |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich Feb. 14, 2025, 9:57 a.m. UTC
  Make md_undefined_symbol() conditional upon dealing with ELF, much like
other architectures (e.g. Arm32 and Arm64) have it. This avoids errors
in gas and even assertions in libbfd when "accidentally" e.g. a COFF-
targeting source file uses "_GLOBAL_OFFSET_TABLE_" for whatever reason.

While there also convert the final return statement to properly use
NULL.

NB: In principle 64-bit Mach-O knows GOT, too. Yet only an i?86-macho
assembler can be built right now, as per configure.tgt. Pretty clearly
adjustments to gotrel[] would also be necessary before these targets
could actually work reasonably cleanly.
---
Afaict the as_bad() in the function can't ever trigger: With one
exception, md_undefined_symbol() is called only after symbol_find() has
already returned NULL. The one exception is symbol_make(), which in turn
has no use where "_GLOBAL_OFFSET_TABLE_" would come into play as a name.
The check here in particular does _not_ guard against a new symbol of
that name being defined (leading to interesting anomalies when in fact
it is). What's the deal? Would lex_got() perhaps better call
md_undefined_symbol() instead of symbol_find_or_make()? Or mimic its
behavior by combining symbol_find() and symbol_new()?

Quite likely the variable GOT_symbol should become ELF-only altogether.
---
v2: New.
  

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -18034,6 +18034,7 @@  i386_target_format (void)
 
 #endif /* ELF / PE / MACH_O  */
 
+#ifdef OBJ_ELF
 symbolS *
 md_undefined_symbol (char *name)
 {
@@ -18051,8 +18052,9 @@  md_undefined_symbol (char *name)
 	};
       return GOT_symbol;
     }
-  return 0;
+  return NULL;
 }
+#endif
 
 #ifdef OBJ_AOUT
 /* Round up a section size to the appropriate boundary.  */
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -144,6 +144,7 @@  int i386_validate_fix (struct fix *);
 extern int tc_i386_fix_adjustable (struct fix *);
 #else
 #define tc_fix_adjustable(X)  ((void)(X), 1)
+#define md_undefined_symbol(N) ((void)(N), NULL)
 #endif
 
 /* Values passed to md_apply_fix don't include the symbol value.  */