Skip to content

Commit a5ff42e

Browse files
committed
Add wrapper for llvm-objcopy
1 parent 6be384c commit a5ff42e

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

tools/gcc-wrapper/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ STRIP_SOURCES = $(SOURCES) strip.c
3636
gcc:
3737
$(CC) -D $(FLAVOR) -I $(SOURCE_DIRECTORY) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) $(GCC_SOURCES) -o $(PREFIX)/gcc-wrapper
3838

39-
strip:
40-
$(CC) -D $(FLAVOR) -I $(SOURCE_DIRECTORY) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) $(STRIP_SOURCES) -o $(PREFIX)/strip-wrapper
39+
binutils:
40+
$(CC) -D $(FLAVOR) -I $(SOURCE_DIRECTORY) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) $(STRIP_SOURCES) -o $(PREFIX)/binutils-wrapper
4141

4242
all: gcc strip

tools/gcc-wrapper/errors.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const char* obggcc_strerror(const int err) {
99
return "Memory allocation failed";
1010
case ERR_UNKNOWN_COMPILER:
1111
return "Unrecognized or unsupported C/C++ compiler";
12+
case ERR_UNKNOWN_BINUTILS_WRAPPER:
13+
return "Unrecognized or unsupported binutils wrapper";
1214
case ERR_GET_APP_FILENAME_FAILURE:
1315
return "Failed to retrieve application filename";
1416
case ERR_EXECVE_FAILURE:

tools/gcc-wrapper/errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define ERR_BINFMT_GUESS_FAILURE -10
1515
#define ERR_FORK_FAILURE -11
1616
#define ERR_EXECVE_SUBPROCESS_FAILURE -12
17+
#define ERR_UNKNOWN_BINUTILS_WRAPPER -13
1718

1819
const char* obggcc_strerror(const int err);
1920

tools/gcc-wrapper/strip.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ extern char** environ;
2020
static const char HYPHEN[] = "-";
2121
static const char BINUTILS_STRIP[] = "strip";
2222

23+
static const char LLVM_STRIP[] = "llvm-strip";
24+
static const char LLVM_OBJCOPY[] = "llvm-objcopy";
25+
26+
static const char LLVM_COMMAND_PREFIX[] = "llvm-";
27+
2328
#define BINFMT_X86_64 (0x01)
2429
#define BINFMT_i386 (0x02)
2530
#define BINFMT_MIPS64EL (0x03)
@@ -203,6 +208,7 @@ int main(int argc, char* argv[], char* envp[]) {
203208
const char* triplet = NULL;
204209
char* input = NULL;
205210

211+
const char* file_name = NULL;
206212
char* parent_directory = NULL;
207213
char* app_filename = NULL;
208214

@@ -269,6 +275,13 @@ int main(int argc, char* argv[], char* envp[]) {
269275
goto end;
270276
}
271277

278+
file_name = basename(app_filename);
279+
280+
if (!(strcmp(file_name, LLVM_STRIP) == 0 || strcmp(file_name, LLVM_OBJCOPY) == 0)) {
281+
err = ERR_UNKNOWN_BINUTILS_WRAPPER;
282+
goto end;
283+
}
284+
272285
parent_directory = malloc(strlen(app_filename) + 1);
273286

274287
if (parent_directory == NULL) {
@@ -314,7 +327,7 @@ int main(int argc, char* argv[], char* envp[]) {
314327

315328
free(executable);
316329

317-
executable = malloc(strlen(parent_directory) + strlen(PATHSEP_S) + strlen(triplet) + strlen(HYPHEN) + strlen(BINUTILS_STRIP) + 1);
330+
executable = malloc(strlen(parent_directory) + strlen(PATHSEP_S) + strlen(triplet) + strlen(HYPHEN) + strlen(file_name) + 1);
318331

319332
if (executable == NULL) {
320333
err = ERR_MEM_ALLOC_FAILURE;
@@ -325,7 +338,7 @@ int main(int argc, char* argv[], char* envp[]) {
325338
strcat(executable, PATHSEP_S);
326339
strcat(executable, triplet);
327340
strcat(executable, HYPHEN);
328-
strcat(executable, BINUTILS_STRIP);
341+
strcat(executable, file_name + strlen(LLVM_COMMAND_PREFIX));
329342

330343
args[0] = executable;
331344
args[kargc] = input;

0 commit comments

Comments
 (0)