Redesign data structures, make basic reladd work.
[centaur.git] / src / options.c
index 014a1f213d32dfc1178f506db6453bafcce108d4..b5018d3dec2a9259d9722ae69bedb2046ddbcf1b 100644 (file)
@@ -11,12 +11,26 @@ static void printUsage(char *progname)
   printf("Usage: %s [OPTIONS] <elf-file>\n", progname);
   printf("\n"
           "Options:\n"
-          "  -h, --help                 Print this help message\n"
-          "  -o, --output               Where to write the modified ELF file to\n"
+          "  -h, --help                     Print this help message\n"
+          "  -o, --output                   Where to write the modified ELF file to\n"
           "\n"
-          "      --print-header         Print ELF header\n"
-          "      --print-segments       Print program headers\n"
-          "      --print-sections       Print sections\n"
+//          "ELF dump:\n"
+//          "      --print-header             Print ELF header\n"
+//          "      --print-segments           Print program headers\n"
+//          "      --print-sections           Print sections\n"
+//          "\n"
+//          "Space insertion:\n"
+//          "    off: File offset, not within any structure (headers or sections).\n"
+//          "    sz:  A multiple of the maximum alignment of all PHDRs.\n"
+//          "\n"
+//          "      --expand-nobits off        Expand virtual areas (NOBITS sections and similar PHDRs).\n"
+//          "      --insert-before off,sz     Insert spacing at given offset,\n"
+//          "                                 mapping everything before it to lower mem addresses.\n"
+//          "      --insert-after  off,sz     Insert spacing at given offset,\n"
+//          "                                 mapping everything after it to higher mem addresses.\n"
+//          "\n"
+          "High-level insertion:\n"
+          "      --reladd        obj.o      Automatically insert object file contents\n"
           "\n");
 }
 
@@ -27,6 +41,7 @@ void parseOptions(CLIOpts *opts, int argc, char **argv)
   char *progname = argv[0];
   int c;
   int option_index = 0;
+  char *endptr;
 
   static struct option long_options[] = {
     {"help", 0, 0, 'h'},
@@ -34,6 +49,10 @@ void parseOptions(CLIOpts *opts, int argc, char **argv)
     {"print-header", 0, 0, 10001},
     {"print-segments", 0, 0, 10002},
     {"print-sections", 0, 0, 10003},
+    {"insert-before", 1, 0, 10004},
+    {"insert-after", 1, 0, 10005},
+    {"expand-nobits", 1, 0, 10006},
+    {"reladd", 1, 0, 10007},
     {NULL, 0, NULL, 0}
   };
 
@@ -55,6 +74,35 @@ void parseOptions(CLIOpts *opts, int argc, char **argv)
       case 10003:
         opts->printSections = 1;
         break;
+      case 10004:
+        opts->insertBeforeOffs = strtoul(optarg, &endptr, 0);
+        if (endptr[0] != ',') {
+          goto USAGE;
+        }
+        opts->insertBeforeSz = strtoul(endptr + 1, &endptr, 0);
+        if (endptr[0] != '\0' || opts->insertBeforeSz == 0) {
+          goto USAGE;
+        }
+        break;
+      case 10005:
+        opts->insertAfterOffs = strtoul(optarg, &endptr, 0);
+        if (endptr[0] != ',') {
+          goto USAGE;
+        }
+        opts->insertAfterSz = strtoul(endptr + 1, &endptr, 0);
+        if (endptr[0] != '\0' || opts->insertAfterSz == 0) {
+          goto USAGE;
+        }
+        break;
+      case 10006:
+        opts->expandNobitsOffs = strtoul(optarg, &endptr, 0);
+        if (endptr[0] != '\0' || opts->expandNobitsOffs < 1) {
+          goto USAGE;
+        }
+        break;
+      case 10007:
+        opts->fnReladd = optarg;
+        break;
       case '?':
       default:
         goto USAGE;