--- gcc/config/winnt/ld.c 2018/04/24 18:20:43 1.1 +++ gcc/config/winnt/ld.c 2018/04/24 18:27:53 1.1.1.2 @@ -1,5 +1,5 @@ /* Call Windows NT 3.x linker. - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright (C) 1994, 1995 Free Software Foundation, Inc. Contributed by Douglas B. Rupp (drupp@cs.washington.edu). This file is part of GNU CC. @@ -16,7 +16,8 @@ GNU General Public License for more deta You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ #include "config.h" #include @@ -26,9 +27,14 @@ the Free Software Foundation, 675 Mass A #include #include +static char *concat (); +static char *concat3 (); + /* These can be set by command line arguments */ char *linker_path = 0; int verbose = 0; +int subsystem = 0; +int entry = 0; int link_arg_max = -1; char **link_args = (char **) 0; @@ -38,6 +44,9 @@ char *search_dirs = "."; static int is_regular_file (char *name); +/* Add the argument contained in STR to the list of arguments to pass to the + linker */ + static void addarg (str) char *str; @@ -62,6 +71,9 @@ addarg (str) link_args [link_arg_index] = str; } +/* Locate the file named in FILE_NAME in the set of paths contained in + PATH_VAL */ + static char * locate_file (file_name, path_val) char *file_name; @@ -110,26 +122,41 @@ locate_file (file_name, path_val) return 0; } +/* Given a library name in NAME, i.e. foo. Look first for libfoo.lib and then + libfoo.a in the set of directories we are allowed to search in */ + static char * expand_lib (name) char *name; { char *lib, *lib_path; - lib = malloc (strlen (name) + 6); + lib = malloc (strlen (name) + 8); strcpy (lib, "lib"); strcat (lib, name); - strcat (lib, ".a"); + strcat (lib, ".lib"); lib_path = locate_file (lib, search_dirs); if (!lib_path) { - fprintf (stderr, "Couldn't locate library: %s\n", lib); - exit (1); + strcpy (lib, "lib"); + strcat (lib, name); + strcat (lib, ".a"); + lib_path = locate_file (lib, search_dirs); + if (!lib_path) + { + fprintf + (stderr, + "Couldn't locate library: lib%s.a or lib%s.lib\n", name, name); + exit (1); + } } return lib_path; } +/* Check to see if the file named in NAME is a regular file, i.e. not a + directory */ + static int is_regular_file (name) char *name; @@ -141,6 +168,9 @@ is_regular_file (name) return !ret && S_ISREG (statbuf.st_mode); } +/* Process the number of args in P_ARGC and contained in ARGV. Look for + special flags, etc. that must be handled for the Microsoft linker */ + static void process_args (p_argc, argv) int *p_argc; @@ -153,9 +183,33 @@ process_args (p_argc, argv) /* -v turns on verbose option here and is passed on to gcc */ if (! strcmp (argv [i], "-v")) verbose = 1; + else if (! strncmp (argv [i], "-g", 2)) + { + addarg ("-debugtype:coff -debug:full"); + } + else if (! strncmp (argv [i], "-stack", 6)) + { + i++; + addarg (concat ("-stack:",argv[i])); + } + else if (! strncmp (argv [i], "-subsystem", 10)) + { + subsystem = 1; + i++; + addarg (concat ("-subsystem:",argv[i])); + } + else if (! strncmp (argv [i], "-e", 2)) + { + entry = 1; + i++; + addarg (concat ("-entry:",&argv[i][1])); + } } } +/* The main program. Spawn the Microsoft linker after fixing up the + Unix-like flags and args to be what the Microsoft linker wants */ + main (argc, argv) int argc; char *argv[]; @@ -170,8 +224,6 @@ main (argc, argv) strcpy (tmppathval, ".;"); pathval = strcat (tmppathval, pathval); - process_args (&argc , argv); - linker_path = locate_file ("link32.exe", pathval); if (!linker_path) { @@ -185,6 +237,10 @@ main (argc, argv) addarg (linker_path); + process_args (&argc , argv); + if (! subsystem) addarg ("-subsystem:console"); + if (! entry) addarg ("-entry:mainCRTStartup"); + for (i = 1; i < argc; i++) { int arg_len = strlen (argv [i]); @@ -203,7 +259,6 @@ main (argc, argv) if (ptr == NULL || strlen (ptr) != 4) strcat (buff, ".exe"); addarg (buff); - addarg ("-debug:full -debugtype:coff"); } else if (arg_len > 2 && !strncmp (argv [i], "-L", 2)) { @@ -225,18 +280,29 @@ main (argc, argv) sdbuff[search_dirs_len+1] = 0; strcat (sdbuff, nbuff); - if (search_dirs) - free (search_dirs); - search_dirs = sdbuff; } else if (arg_len > 2 && !strncmp (argv [i], "-l", 2)) - addarg (expand_lib (&argv[i][2])); - else if (!strcmp (argv [i], "-v")) - ; - else - addarg (argv [i]); + { + addarg (expand_lib (&argv[i][2])); + } + else if (!strcmp (argv [i], "-v") + || !strcmp (argv [i], "-g") + || !strcmp (argv [i], "-noinhibit-exec")) + { + ; + } + else if (!strcmp (argv [i], "-stack") + || !strcmp (argv [i], "-subsystem") + || !strcmp (argv [i], "-e")) + { + i++; + } + else + { + addarg (argv [i]); + } } addarg (NULL); @@ -258,3 +324,25 @@ main (argc, argv) exit (0); } + +static char * +concat (s1, s2) + char *s1, *s2; +{ + int len1 = strlen (s1); + int len2 = strlen (s2); + char *result = malloc (len1 + len2 + 1); + + strcpy (result, s1); + strcpy (result + len1, s2); + *(result + len1 + len2) = 0; + + return result; +} + +static char * +concat3 (s1, s2, s3) + char *s1, *s2, *s3; +{ + return concat (concat (s1, s2), s3); +}