Skip to content

Commit

Permalink
collect2.c (main): Call find_file_set_debug.
Browse files Browse the repository at this point in the history
2012-11-27  Meador Inge  <[email protected]>

	* collect2.c (main): Call find_file_set_debug.
	(find_a_find, add_prefix, prefix_from_env, prefix_from_string):
	Factor out into ...
	* file-find.c (New file): ... here and ...
	* file-find.h (New file): ... here.
	* gcc-ar.c (standard_exec_prefix): New variable.
	(standard_libexec_prefix): Ditto.
	(tooldir_base_prefix) Ditto.
	(self_exec_prefix): Ditto.
	(self_libexec_prefix): Ditto.
	(self_tooldir_prefix): Ditto.
	(target_version): Ditto.
	(path): Ditto.
	(target_path): Ditto.
	(setup_prefixes): New function.
	(main): Rework how wrapped programs are found.
	* Makefile.in (OBJS-libcommon-target): Add file-find.o.
	(AR_OBJS): New variable.
	(gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
	(gcc-nm$(exeext)): Ditto.
	(gcc-ranlib(exeext)): Ditto.
	(COLLECT2_OBJS): Add file-find.o.
	(collect2.o): Add file-find.h prerequisite.
	(file-find.o): New rule.

From-SVN: r193859
  • Loading branch information
meadori authored and Meador Inge committed Nov 27, 2012
1 parent 3a50da3 commit c2a73de
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 221 deletions.
27 changes: 27 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
2012-11-27 Meador Inge <[email protected]>

* collect2.c (main): Call find_file_set_debug.
(find_a_find, add_prefix, prefix_from_env, prefix_from_string):
Factor out into ...
* file-find.c (New file): ... here and ...
* file-find.h (New file): ... here.
* gcc-ar.c (standard_exec_prefix): New variable.
(standard_libexec_prefix): Ditto.
(tooldir_base_prefix) Ditto.
(self_exec_prefix): Ditto.
(self_libexec_prefix): Ditto.
(self_tooldir_prefix): Ditto.
(target_version): Ditto.
(path): Ditto.
(target_path): Ditto.
(setup_prefixes): New function.
(main): Rework how wrapped programs are found.
* Makefile.in (OBJS-libcommon-target): Add file-find.o.
(AR_OBJS): New variable.
(gcc-ar$(exeext)): Add dependency on $(AR_OBJS).
(gcc-nm$(exeext)): Ditto.
(gcc-ranlib(exeext)): Ditto.
(COLLECT2_OBJS): Add file-find.o.
(collect2.o): Add file-find.h prerequisite.
(file-find.o): New rule.

2010-11-27 Dehao Chen <[email protected]>

* ipa-prop.c (ipa_modify_call_arguments): Set loc correctly.
Expand Down
20 changes: 11 additions & 9 deletions gcc/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ OBJS-libcommon = diagnostic.o pretty-print.o intl.o input.o version.o
# compiler and containing target-dependent code.
OBJS-libcommon-target = $(common_out_object_file) prefix.o params.o \
opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \
hash-table.o
hash-table.o file-find.o

# This lists all host objects for the front ends.
ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
Expand Down Expand Up @@ -1852,19 +1852,20 @@ graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) toplev.h $(DIAGNOSTIC_CORE_H) $
sbitmap.o: sbitmap.c sbitmap.h $(CONFIG_H) $(SYSTEM_H) coretypes.h
sparseset.o: sparseset.c $(SYSTEM_H) sparseset.h $(CONFIG_H)

AR_OBJS = file-find.o
AR_LIBS = @COLLECT2_LIBS@

gcc-ar$(exeext): gcc-ar.o $(LIBDEPS)
gcc-ar$(exeext): gcc-ar.o $(AR_OBJS) $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) gcc-ar.o -o $@ \
$(LIBS) $(AR_LIBS)
$(AR_OBJS) $(LIBS) $(AR_LIBS)

gcc-nm$(exeext): gcc-nm.o $(LIBDEPS)
gcc-nm$(exeext): gcc-nm.o $(AR_OBJS) $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) gcc-nm.o -o $@ \
$(LIBS) $(AR_LIBS)
$(AR_OBJS) $(LIBS) $(AR_LIBS)

gcc-ranlib$(exeext): gcc-ranlib.o $(LIBDEPS)
gcc-ranlib$(exeext): gcc-ranlib.o $(AR_OBJS) $(LIBDEPS)
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) gcc-ranlib.o -o $@ \
$(LIBS) $(AR_LIBS)
$(AR_OBJS) $(LIBS) $(AR_LIBS)

CFLAGS-gcc-ar.o += $(DRIVER_DEFINES) \
-DTARGET_MACHINE=\"$(target_noncanonical)\" \
Expand Down Expand Up @@ -1892,7 +1893,7 @@ gcc-ranlib.c: gcc-ar.c
gcc-nm.c: gcc-ar.c
cp $^ $@

COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o vec.o ggc-none.o
COLLECT2_OBJS = collect2.o collect2-aix.o tlink.o vec.o ggc-none.o file-find.o
COLLECT2_LIBS = @COLLECT2_LIBS@
collect2$(exeext): $(COLLECT2_OBJS) $(LIBDEPS)
# Don't try modifying collect2 (aka ld) in place--it might be linking this.
Expand All @@ -1904,7 +1905,7 @@ CFLAGS-collect2.o += -DTARGET_MACHINE=\"$(target_noncanonical)\" \
@TARGET_SYSTEM_ROOT_DEFINE@
collect2.o : collect2.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) intl.h \
$(OBSTACK_H) $(DEMANGLE_H) collect2.h collect2-aix.h version.h \
$(DIAGNOSTIC_H)
$(DIAGNOSTIC_H) file-find.h

collect2-aix.o : collect2-aix.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
collect2-aix.h
Expand Down Expand Up @@ -3425,6 +3426,7 @@ hw-doloop.o : hw-doloop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h dumpfile.h $(TM_H)
$(RTL_H) $(FLAGS_H) $(EXPR_H) hard-reg-set.h $(BASIC_BLOCK_H) $(TM_P_H) \
$(DF_H) $(CFGLOOP_H) $(RECOG_H) $(TARGET_H) \
$(REGS_H) hw-doloop.h
file-find.o: file-find.c $(CONFIG_H) $(SYSTEM_H) file-find.h
$(out_object_file): $(out_file) $(CONFIG_H) coretypes.h $(TM_H) $(TREE_H) \
$(RTL_H) $(REGS_H) hard-reg-set.h insn-config.h conditions.h \
output.h $(INSN_ATTR_H) $(SYSTEM_H) toplev.h $(DIAGNOSTIC_CORE_H) \
Expand Down
184 changes: 2 additions & 182 deletions gcc/collect2.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "tm.h"
#include "filenames.h"
#include "file-find.h"

/* TARGET_64BIT may be defined to use driver specific functionality. */
#undef TARGET_64BIT
Expand Down Expand Up @@ -243,22 +244,6 @@ static const char *target_system_root = "";
would leave untouched. */
bool may_unlink_output_file = false;

/* Structure to hold all the directories in which to search for files to
execute. */

struct prefix_list
{
const char *prefix; /* String to prepend to the path. */
struct prefix_list *next; /* Next in linked list. */
};

struct path_prefix
{
struct prefix_list *plist; /* List of prefixes to try */
int max_len; /* Max length of a prefix in PLIST */
const char *name; /* Name of this list (used in config stuff) */
};

#ifdef COLLECT_EXPORT_LIST
/* Lists to keep libraries to be scanned for global constructors/destructors. */
static struct head libs; /* list of libraries */
Expand Down Expand Up @@ -302,10 +287,6 @@ typedef enum {
static symkind is_ctor_dtor (const char *);

static void handler (int);
static char *find_a_file (struct path_prefix *, const char *);
static void add_prefix (struct path_prefix *, const char *);
static void prefix_from_env (const char *, struct path_prefix *);
static void prefix_from_string (const char *, struct path_prefix *);
static void do_wait (const char *, struct pex_obj *);
static void fork_execute (const char *, char **);
static void maybe_unlink (const char *);
Expand Down Expand Up @@ -653,168 +634,6 @@ static const char *const target_machine = TARGET_MACHINE;
Return 0 if not found, otherwise return its name, allocated with malloc. */

static char *
find_a_file (struct path_prefix *pprefix, const char *name)
{
char *temp;
struct prefix_list *pl;
int len = pprefix->max_len + strlen (name) + 1;

if (debug)
fprintf (stderr, "Looking for '%s'\n", name);

#ifdef HOST_EXECUTABLE_SUFFIX
len += strlen (HOST_EXECUTABLE_SUFFIX);
#endif

temp = XNEWVEC (char, len);

/* Determine the filename to execute (special case for absolute paths). */

if (IS_ABSOLUTE_PATH (name))
{
if (access (name, X_OK) == 0)
{
strcpy (temp, name);

if (debug)
fprintf (stderr, " - found: absolute path\n");

return temp;
}

#ifdef HOST_EXECUTABLE_SUFFIX
/* Some systems have a suffix for executable files.
So try appending that. */
strcpy (temp, name);
strcat (temp, HOST_EXECUTABLE_SUFFIX);

if (access (temp, X_OK) == 0)
return temp;
#endif

if (debug)
fprintf (stderr, " - failed to locate using absolute path\n");
}
else
for (pl = pprefix->plist; pl; pl = pl->next)
{
struct stat st;

strcpy (temp, pl->prefix);
strcat (temp, name);

if (stat (temp, &st) >= 0
&& ! S_ISDIR (st.st_mode)
&& access (temp, X_OK) == 0)
return temp;

#ifdef HOST_EXECUTABLE_SUFFIX
/* Some systems have a suffix for executable files.
So try appending that. */
strcat (temp, HOST_EXECUTABLE_SUFFIX);

if (stat (temp, &st) >= 0
&& ! S_ISDIR (st.st_mode)
&& access (temp, X_OK) == 0)
return temp;
#endif
}

if (debug && pprefix->plist == NULL)
fprintf (stderr, " - failed: no entries in prefix list\n");

free (temp);
return 0;
}

/* Add an entry for PREFIX to prefix list PPREFIX. */

static void
add_prefix (struct path_prefix *pprefix, const char *prefix)
{
struct prefix_list *pl, **prev;
int len;

if (pprefix->plist)
{
for (pl = pprefix->plist; pl->next; pl = pl->next)
;
prev = &pl->next;
}
else
prev = &pprefix->plist;

/* Keep track of the longest prefix. */

len = strlen (prefix);
if (len > pprefix->max_len)
pprefix->max_len = len;

pl = XNEW (struct prefix_list);
pl->prefix = xstrdup (prefix);

if (*prev)
pl->next = *prev;
else
pl->next = (struct prefix_list *) 0;
*prev = pl;
}

/* Take the value of the environment variable ENV, break it into a path, and
add of the entries to PPREFIX. */

static void
prefix_from_env (const char *env, struct path_prefix *pprefix)
{
const char *p;
p = getenv (env);

if (p)
prefix_from_string (p, pprefix);
}

static void
prefix_from_string (const char *p, struct path_prefix *pprefix)
{
const char *startp, *endp;
char *nstore = XNEWVEC (char, strlen (p) + 3);

if (debug)
fprintf (stderr, "Convert string '%s' into prefixes, separator = '%c'\n", p, PATH_SEPARATOR);

startp = endp = p;
while (1)
{
if (*endp == PATH_SEPARATOR || *endp == 0)
{
strncpy (nstore, startp, endp-startp);
if (endp == startp)
{
strcpy (nstore, "./");
}
else if (! IS_DIR_SEPARATOR (endp[-1]))
{
nstore[endp-startp] = DIR_SEPARATOR;
nstore[endp-startp+1] = 0;
}
else
nstore[endp-startp] = 0;

if (debug)
fprintf (stderr, " - add prefix: %s\n", nstore);

add_prefix (pprefix, nstore);
if (*endp == 0)
break;
endp = startp = endp + 1;
}
else
endp++;
}
free (nstore);
}

#ifdef OBJECT_FORMAT_NONE

/* Add an entry for the object file NAME to object file list LIST.
Expand Down Expand Up @@ -1198,6 +1017,7 @@ main (int argc, char **argv)
#endif
}
vflag = debug;
find_file_set_debug (debug);
if (no_partition && lto_mode == LTO_MODE_WHOPR)
lto_mode = LTO_MODE_LTO;
}
Expand Down
Loading

0 comments on commit c2a73de

Please sign in to comment.