@@ -16,27 +16,33 @@ Author: Michael Tautschnig, 2018
16
16
17
17
#include < cstring>
18
18
19
+ std::string objcopy_command (const std::string &compiler_or_linker)
20
+ {
21
+ if (has_suffix (compiler_or_linker, " -ld" ))
22
+ {
23
+ std::string objcopy_cmd = compiler_or_linker;
24
+ objcopy_cmd.erase (objcopy_cmd.size () - 2 );
25
+ objcopy_cmd += " objcopy" ;
26
+
27
+ return objcopy_cmd;
28
+ }
29
+ else
30
+ return " objcopy" ;
31
+ }
32
+
19
33
int hybrid_binary (
20
34
const std::string &compiler_or_linker,
21
35
const std::string &goto_binary_file,
22
36
const std::string &output_file,
23
- message_handlert &message_handler)
37
+ message_handlert &message_handler,
38
+ bool linking_efi)
24
39
{
25
40
messaget message (message_handler);
26
41
27
- int result;
42
+ int result = 0 ;
28
43
29
44
#if defined(__linux__) || defined(__FreeBSD_kernel__)
30
- std::string objcopy_cmd;
31
-
32
- if (has_suffix (compiler_or_linker, " -ld" ))
33
- {
34
- objcopy_cmd = compiler_or_linker;
35
- objcopy_cmd.erase (objcopy_cmd.size () - 2 );
36
- objcopy_cmd += " objcopy" ;
37
- }
38
- else
39
- objcopy_cmd = " objcopy" ;
45
+ const std::string objcopy_cmd = objcopy_command (compiler_or_linker);
40
46
41
47
// merge output from gcc or ld with goto-binary using objcopy
42
48
@@ -52,7 +58,15 @@ int hybrid_binary(
52
58
" --remove-section" , " goto-cc" ,
53
59
" --add-section" , " goto-cc=" + goto_binary_file, output_file};
54
60
55
- result = run (objcopy_argv[0 ], objcopy_argv);
61
+ const int add_section_result = run (objcopy_argv[0 ], objcopy_argv);
62
+ if (add_section_result != 0 )
63
+ {
64
+ if (linking_efi)
65
+ message.warning () << " cannot merge EFI binaries: goto-cc section lost"
66
+ << messaget::eom;
67
+ else
68
+ result = add_section_result;
69
+ }
56
70
}
57
71
58
72
// delete the goto binary
0 commit comments