Files
binutils-gdb/include/same-inode.h
H.J. Lu d048eee291 ld: Use stat to check if linker script appears multiple times
Use stat, instead of strcmp, to check if the same linker script file
appears multiple times for

$ ld -L... -T ././/script.t -T script.t ...

Although ././/script.t and script.t access the same file, but their
filenames are different.  strcmp won't work here.

Copy gnulib/import/same-inode.h to include since the gnulib directory
isn't included in the binutils tarball.

include/

	PR ld/24576
	* same-inode.h: New file.  Copied from gnulib/import/same-inode.h.

ld/

	PR ld/24576
	* ldfile.c: Include "same-inode.h".
	(ldfile_find_command_file): Change the second argument from bool
	to enum script_open_style.  Check if the same linker script file
	appears multiple times by using stat, instead using strcmp.
	(ldfile_open_command_file_1): Don't check if the same linker
	script file appears multiple times here.
	* testsuite/ld-scripts/pr24576-1.d: Adjusted.
	* testsuite/ld-scripts/pr24576-2.d: New.
	* testsuite/ld-scripts/script.exp: Run pr24576-2.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-14 08:00:04 -07:00

48 lines
1.7 KiB
C

/* Determine whether two stat buffers are known to refer to the same file.
Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef SAME_INODE_H
# define SAME_INODE_H 1
# include <sys/types.h>
# if defined __VMS && __CRTL_VER < 80200000
# define SAME_INODE(a, b) \
((a).st_ino[0] == (b).st_ino[0] \
&& (a).st_ino[1] == (b).st_ino[1] \
&& (a).st_ino[2] == (b).st_ino[2] \
&& (a).st_dev == (b).st_dev)
# elif defined _WIN32 && ! defined __CYGWIN__
/* Native Windows. */
# if _GL_WINDOWS_STAT_INODES
/* stat() and fstat() set st_dev and st_ino to 0 if information about
the inode is not available. */
# define SAME_INODE(a, b) \
(!((a).st_ino == 0 && (a).st_dev == 0) \
&& (a).st_ino == (b).st_ino && (a).st_dev == (b).st_dev)
# else
/* stat() and fstat() set st_ino to 0 always. */
# define SAME_INODE(a, b) 0
# endif
# else
# define SAME_INODE(a, b) \
((a).st_ino == (b).st_ino \
&& (a).st_dev == (b).st_dev)
# endif
#endif