@@ -450,6 +450,21 @@ static bool processCppMacroX (vString *identifier, int lastChar, vString *line)
450450 return r ;
451451}
452452
453+ static bool isEligibleAsSectionName (const vString * str )
454+ {
455+ char * c = vStringValue (str );
456+ while (* c )
457+ {
458+ if (!(isalnum (((unsigned char )* c ))
459+ || (* c == '.' )
460+ || (* c == '-' )
461+ || (* c == '_' )))
462+ return false;
463+ c ++ ;
464+ }
465+ return true;
466+ }
467+
453468static const unsigned char * readLineViaCpp (const char * commentChars )
454469{
455470 static vString * line ;
@@ -475,10 +490,39 @@ static const unsigned char *readLineViaCpp (const char *commentChars)
475490 continue ;
476491
477492 /* We cannot store these values to vString
478- * Store a whitespace as a dummy value for them.
493+ * Store a whitespace as a dummy value for them, but.. .
479494 */
480495 if (!truncation )
496+ {
481497 vStringPut (line , ' ' );
498+
499+ /* Quoted from the info document of Gas:
500+ -------------------------------------
501+ For ELF targets, the assembler supports another type of '.section'
502+ directive for compatibility with the Solaris assembler:
503+
504+ .section "NAME"[, FLAGS...]
505+ -------------------------------------
506+
507+ If we replace "..." with ' ' here, we can lost the name
508+ of the section. */
509+ const vString * str = cppGetLastCharOrStringContents ();
510+ if (str )
511+ {
512+ const char * section = strrstr (vStringValue (line ), ".section" );
513+ if (section && isEligibleAsSectionName (str ))
514+ {
515+ section += strlen (".section" );
516+ while (isspace ((unsigned char )* section ))
517+ section ++ ;
518+ if (* section == '\0' )
519+ {
520+ vStringCat (line , str );
521+ vStringPut (line , ' ' );
522+ }
523+ }
524+ }
525+ }
482526 }
483527 else if (c == '\n' || (extraLinesepChars [0 ] != '\0'
484528 && strchr (extraLinesepChars , c ) != NULL ))
0 commit comments