@@ -45,6 +45,8 @@ typedef struct {
4545 enum SourceType src_type ;
4646 uint32_t stack_size ;
4747 bool nodefaultlibs , nostdlib , nostdinc ;
48+
49+ WasmLinkerOptions linker_opts ;
4850} Options ;
4951
5052static Vector remove_on_exit ;
@@ -232,6 +234,38 @@ int compile_csource(const char *src, const char *ofn, Vector *obj_files, Options
232234 return 0 ;
233235}
234236
237+ static void parse_linker_options (const char * arg , WasmLinkerOptions * lopts ) {
238+ const char * arg_bak = arg ;
239+ if (* arg != '-' )
240+ return ;
241+ ++ arg ;
242+
243+ enum {
244+ OPT_ALLOW_UNDEFINED ,
245+ };
246+ static const struct option kOptions [] = {
247+ {"-allow-undefined" , no_argument , OPT_ALLOW_UNDEFINED },
248+
249+ {NULL },
250+ };
251+
252+ for (int i = 0 ; ; ++ i ) {
253+ if (kOptions [i ].name == NULL )
254+ break ;
255+ if (strcmp (arg , kOptions [i ].name ) == 0 ) {
256+ switch (kOptions [i ].val ) {
257+ default : assert (false); break ;
258+ case OPT_ALLOW_UNDEFINED :
259+ lopts -> allow_undefined = true;
260+ break ;
261+ }
262+ return ;
263+ }
264+ }
265+ fprintf (stderr , "Warning: unknown option: %s\n" , arg_bak );
266+ }
267+
268+
235269static void parse_options (int argc , char * argv [], Options * opts ) {
236270 enum {
237271 OPT_HELP = 128 ,
@@ -470,6 +504,11 @@ static void parse_options(int argc, char *argv[], Options *opts) {
470504 * p = true;
471505 break ;
472506 }
507+
508+ const char * arg = argv [optind - 1 ];
509+ if (strncmp (arg , "-Wl," , 4 ) == 0 ) {
510+ parse_linker_options (arg + 4 , & opts -> linker_opts );
511+ }
473512 }
474513 // Fallthrough
475514 case OPT_WNO :
@@ -534,6 +573,7 @@ static int do_link(Vector *obj_files, Options *opts) {
534573 WasmLinker linker_body ;
535574 WasmLinker * linker = & linker_body ;
536575 linker_init (linker );
576+ linker -> options = opts -> linker_opts ;
537577
538578 for (int i = 0 ; i < obj_files -> len ; ++ i ) {
539579 const char * objfn = obj_files -> data [i ];
0 commit comments