summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/gcc.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-03-08 05:29:49 +0000
committerpeter <peter@FreeBSD.org>1998-03-08 05:29:49 +0000
commitc39aed21a8d0e0849e9678f826151961a0762e3b (patch)
treea6ca8932d003c3051dc60b05e31670c8902de0bb /contrib/gcc/gcc.c
parent2bddba52f1a956b695317bf8be9a633f302c4df3 (diff)
downloadFreeBSD-src-c39aed21a8d0e0849e9678f826151961a0762e3b.zip
FreeBSD-src-c39aed21a8d0e0849e9678f826151961a0762e3b.tar.gz
First round of changes to support generation of assembler for the old
a.out gas and the binutils gas (elf or a.out) with a single compiler. This uses other infrastructure not yet committed, in order to support both a.out and elf it needs to be able to get to both a.out and elf gas, ld, libs, crt* etc. So for now, the support is pretty much dormant. The new freebsd.h file is based on the old freebsd-elf.h file (which has a long lineage, right back through linux and svr4 files). The change is pretty dramatic from a gcc internals standpoint as it overrides a lot of definitions in order to generate different output based on target mode. There is potential for screw-ups, so please be on the lookout - gcc's configuration mechanism wasn't really meant for this kind of thing. It's believed to compile world etc just fine under both a.out and elf, can handle global constructors and destructors, handles the differences in a.out and elf stabs, and what sections things like exceptions go in. The initial idea came from i386/osfrose.h which is a dual rose/elf format target. These two are not as diverse as a.out and elf it would seem. The cc front-end uses external configuration to determine default object format (still being thrashed out, so read the source if you want to see it so far), and has a '-aout' and '-elf' override command line switch. There are some other internal switches that can be accessed, namely -maout, -mno-aout, -munderscores and -mnounderscores. The underscore and local symbol prefixing rules are controllable seperately to the output format. (ie: it's possible to generate a.out without the _ prefixes on symbols and also to generate elf with the _ prefixes. This isn't quite optimal, but does seem to work pretty well, except the linkers don't always recognise the local symbols without their normal names) The default format is a.out (still), nobody should see any major changes. With both elf and a.out tools and libraries installed: [1:26pm]/tmp-223> cc -elf -o hello hello.c peter@beast[1:27pm]/tmp-224> file hello hello: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked, not stripped [1:27pm]/tmp-225> ./hello hello world! [1:27pm]/tmp-226> cc -aout -o hello hello.c [1:27pm]/tmp-227> file hello hello: FreeBSD/i386 compact demand paged dynamically linked executable not stripped 1:27pm]/tmp-228> ./hello hello world! Since my co-conspirators put a lot of effort into this too, I'll add them so they can share the blame^H^H^H^H^Hglory. :-) Reviewed by: sos, jdp
Diffstat (limited to 'contrib/gcc/gcc.c')
-rw-r--r--contrib/gcc/gcc.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/contrib/gcc/gcc.c b/contrib/gcc/gcc.c
index c40097e..d234c1d 100644
--- a/contrib/gcc/gcc.c
+++ b/contrib/gcc/gcc.c
@@ -2327,6 +2327,14 @@ struct infile
char *language;
};
+#if defined(FREEBSD_NATIVE)
+#if defined(FREEBSD_AOUT) /* XXX: revisit this */
+static int objformat_aout = 1; /* set default format in absense of */
+#else /* any other hints. */
+static int objformat_aout = 0;
+#endif
+#endif
+
/* Also a vector of input files specified. */
static struct infile *infiles;
@@ -2472,6 +2480,39 @@ process_command (argc, argv)
}
}
+#if defined(FREEBSD_NATIVE)
+ {
+ /* first hint is /etc/objectformat */
+ FILE *fp = fopen("/etc/objectformat", "r");
+ if (fp) {
+ char buf[1024];
+ buf[1023] = '\0';
+ while (fgets(buf, sizeof(buf) - 1, fp) != NULL) {
+ i = strlen(buf);
+ if (buf[i - 1] == '\n')
+ buf[i - 1] = '\0';
+ if (strcmp(buf, "OBJFORMAT=aout") == 0)
+ objformat_aout = 1;
+ else if (strcmp(buf, "OBJFORMAT=elf") == 0)
+ objformat_aout = 0;
+ else
+ fprintf(stderr, "Unrecognized line in /etc/objectformat: %s\n", buf);
+ }
+ fclose(fp);
+ }
+ /* but the user $OBJFORMAT overrides system default */
+ temp = getenv("OBJFORMAT");
+ if (temp) {
+ if (strcmp(temp, "aout") == 0)
+ objformat_aout = 1;
+ else if (strcmp(temp, "elf") == 0)
+ objformat_aout = 0;
+ else
+ fprintf(stderr, "Unrecognized value of $OBJFORMAT: %s\n", temp);
+ }
+ }
+#endif
+
/* Convert new-style -- options to old-style. */
translate_options (&argc, &argv);
@@ -2481,6 +2522,19 @@ process_command (argc, argv)
for (i = 1; i < argc; i++)
{
+#if defined(FREEBSD_NATIVE)
+ /* .. and command line args override all */
+ if (strcmp (argv[i], "-aout") == 0)
+ {
+ objformat_aout = 1;
+ continue;
+ }
+ else if (strcmp (argv[i], "-elf") == 0)
+ {
+ objformat_aout = 0;
+ continue;
+ }
+#endif
if (! strcmp (argv[i], "-dumpspecs"))
{
printf ("*asm:\n%s\n\n", asm_spec);
@@ -2707,6 +2761,11 @@ process_command (argc, argv)
/* Use 2 as fourth arg meaning try just the machine as a suffix,
as well as trying the machine and the version. */
#ifdef FREEBSD_NATIVE
+ if (objformat_aout) {
+ n_switches++; /* add implied -maout */
+ add_prefix (&exec_prefixes, "/usr/libexec/aout/", 0, 0, NULL_PTR);
+ } else
+ add_prefix (&exec_prefixes, "/usr/libexec/elf/", 0, 0, NULL_PTR);
add_prefix (&exec_prefixes, "/usr/libexec/", 0, 0, NULL_PTR);
add_prefix (&exec_prefixes, "/usr/bin/", 0, 0, NULL_PTR);
add_prefix (&startfile_prefixes, "/usr/libdata/gcc/", 0, 0, NULL_PTR);
@@ -2779,6 +2838,19 @@ process_command (argc, argv)
to the copy in the vector of switches.
Store all the infiles in their vector. */
+#ifdef FREEBSD_NATIVE
+ if (objformat_aout == 1) {
+ switches[n_switches].part1 = "maout";
+ switches[n_switches].args = 0;
+ switches[n_switches].live_cond = 0;
+ switches[n_switches].valid = 0;
+ n_switches++;
+ putenv("OBJFORMAT=aout");
+ } else {
+ putenv("OBJFORMAT=elf");
+ }
+#endif
+
for (i = 1; i < argc; i++)
{
/* Just skip the switches that were handled by the preceding loop. */
@@ -2798,6 +2870,12 @@ process_command (argc, argv)
;
else if (! strcmp (argv[i], "-print-multi-directory"))
;
+#ifdef FREEBSD_NATIVE
+ else if (! strcmp (argv[i], "-aout"))
+ ;
+ else if (! strcmp (argv[i], "-elf"))
+ ;
+#endif
else if (argv[i][0] == '+' && argv[i][1] == 'e')
{
/* Compensate for the +e options to the C++ front-end;
OpenPOWER on IntegriCloud