Skip to content

Commit 0098b9b

Browse files
committed
Asm: extract section names quoted with double quote characters
The original code could not extract .inittext in .section ".inittext","ax" Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 3d7fd14 commit 0098b9b

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

Units/parser-asm.r/gas-section.d/expected.tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ machine/asm.h input.s /^#include <machine\/asm.h>/;" h roles:system
22
.rodata.cst8 input.s /^ .section .rodata.cst8,"aM",@progbits,8$/;" s roles:placement
33
one input.s /^one: .double 1.0$/;" l roles:def
44
limit input.s /^limit: .double 0.29$/;" l roles:def
5+
.inittext input-0.s /^ .section ".inittext","ax"$/;" s roles:placement
6+
intcall input-0.s /^intcall:$/;" l roles:def
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Taken from linux/arch/x86/boot/bioscall.S */
2+
3+
/*
4+
* "Glove box" for BIOS calls. Avoids the constant problems with BIOSes
5+
* touching registers they shouldn't be.
6+
*/
7+
8+
.code16
9+
.section ".inittext","ax"
10+
.globl intcall
11+
.type intcall, @function
12+
intcall:
13+
/* Self-modify the INT instruction. Ugly, but works. */
14+
cmpb %al, 3f

parsers/asm.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
453468
static 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

Comments
 (0)