@@ -385,15 +385,43 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
385
385
386
386
if let Some ( section_name) = section_name {
387
387
let ( segment_name, section_name) = if tcx. sess . target . is_like_osx {
388
- let section_name = section_name. as_str ( ) ;
389
- if let Some ( names) = section_name. split_once ( ',' ) {
390
- names
391
- } else {
388
+ // See https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCSectionMachO.cpp
389
+ let mut parts = section_name. as_str ( ) . split ( ',' ) ;
390
+ let Some ( segment_name) = parts. next ( ) else {
392
391
tcx. dcx ( ) . fatal ( format ! (
393
392
"#[link_section = \" {}\" ] is not valid for macos target: must be segment and section separated by comma" ,
394
393
section_name
395
394
) ) ;
395
+ } ;
396
+ let Some ( section_name) = parts. next ( ) else {
397
+ tcx. dcx ( ) . fatal ( format ! (
398
+ "#[link_section = \" {}\" ] is not valid for macos target: must be segment and section separated by comma" ,
399
+ section_name
400
+ ) ) ;
401
+ } ;
402
+ if section_name. len ( ) > 16 {
403
+ tcx. dcx ( ) . fatal ( format ! (
404
+ "#[link_section = \" {}\" ] is not valid for macos target: section name bigger than 16 bytes" ,
405
+ section_name
406
+ ) ) ;
407
+ }
408
+ let section_type = parts. next ( ) . unwrap_or ( "regular" ) ;
409
+ if section_type != "regular" && section_type != "cstring_literals" {
410
+ tcx. dcx ( ) . fatal ( format ! (
411
+ "#[link_section = \" {}\" ] is not supported: unsupported section type {}" ,
412
+ section_name, section_type,
413
+ ) ) ;
414
+ }
415
+ let _attrs = parts. next ( ) ;
416
+ if parts. next ( ) . is_some ( ) {
417
+ tcx. dcx ( ) . fatal ( format ! (
418
+ "#[link_section = \" {}\" ] is not valid for macos target: too many components" ,
419
+ section_name
420
+ ) ) ;
396
421
}
422
+ // FIXME(bytecodealliance/wasmtime#8901) set S_CSTRING_LITERALS section type when
423
+ // cstring_literals is specified
424
+ ( segment_name, section_name)
397
425
} else {
398
426
( "" , section_name. as_str ( ) )
399
427
} ;
0 commit comments