RFC: PR 31761: Stop the linker from overwriting source files

Andreas Schwab schwab@linux-m68k.org
Tue Jun 18 17:23:13 GMT 2024


On Jun 18 2024, Nick Clifton wrote:

> +/* Returns TRUE if NAME has an extension that is known to be used
> +   by typical input files to the linker, or input files to a build
> +   system that eventually ends up invoking the linker.  */
> +
> +static bool
> +has_known_file_extension (const char * name)
> +{
> +  if (name == NULL)
> +    return false;
> +
> +  size_t namelen = strlen (name);
> +
> +  if (namelen < 3)
> +    return false;
> +
> +  /* FIXME: We could optimize this lookup a lot.  But it is coded
> +     this way for simplicity and ease of extension.  */
> +  static const char * extensions[] =
> +    {
> +      ".c", ".h", ".s", ".C", ".S", ".o", ".t",
> +      ".ld",
> +      ".cpp", ".cxx"
> +    };
> +
> +  size_t i;
> +  for (i = 0; i < ARRAY_SIZE (extensions); i++)
> +    {
> +      size_t len = strlen (extensions[i]);
> +
> +      if (strcmp (name + namelen - len, extensions[i]) == 0)

This can be undefined if len > 3.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


More information about the Binutils mailing list