Bug 22714 - Assembler preprocessor loses track of \@
Summary: Assembler preprocessor loses track of \@
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: 2.31
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-15 17:22 UTC by Wolfgang Ocker
Modified: 2018-03-31 12:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2018-01-31 00:00:00


Attachments
This archive contains the sample files demonstrating the problem (18.05 KB, application/x-compressed-tar)
2018-01-15 17:22 UTC, Wolfgang Ocker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Ocker 2018-01-15 17:22:57 UTC
Created attachment 10750 [details]
This archive contains the sample files demonstrating the problem

OS: Fedora 27, all updates

arm-linux-gnueabi-as, version 2.29.1, build from sources

$ arm-linux-gnueabi-as -version
GNU assembler (GNU Binutils) 2.29.1
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `arm-linux-gnueabi'.

The attached file "entry-armv-okay-1. s" can be translated, the file "entry-armv-fail-1. s" cannot. The error message is:

/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/kernel/entry-header.S: Assembler messages:
/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/kernel/entry-header.S:319: Warning: stray `\'
/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/kernel/entry-armv.S:773: Warning: stray `\'
/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/kernel/entry-armv.S:773: Error: bad expression

Command line:

arm-linux-gnueabi-as entry-armv-fail-1.s

The files differ in this way:

--- entry-armv-okay-1.s	2018-01-15 17:03:30.339301143 +0100
+++ entry-armv-fail-1.s	2018-01-15 17:00:43.578260650 +0100
@@ -7,7 +7,7 @@
 
 
 # 1 "./include/generated/autoconf.h" 1
-# 16 "/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/include/linux/kconfig.h" 2
+# 6 "/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/include/linux/kconfig.h" 2
 # 1 "<command-line>" 2
 # 1 "/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/include/asm/unified.h" 1
 # 74 "/home/user/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/kernel/linux/arch/arm/include/asm/unified.h"

The error also occurs in other variations. The long file paths in the comments, inserted by the preprocessor, are striking. 
I also observed the bug with the assembler v2.28 (stable Debian).

The file comes from the Linux kernel: arch/arm/kernel/entry-armv.S (preprocessed)
Comment 1 Sourceware Commits 2018-01-31 06:31:53 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ab1fadc6b2f057b817e1fc093650b63d9f6dd6c5

commit ab1fadc6b2f057b817e1fc093650b63d9f6dd6c5
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jan 31 13:34:18 2018 +1030

    PR22714, Assembler preprocessor loses track of \@
    
    The PR22714 testcase is such that the input buffer processed by
    do_scrub_chars ends on this line
    
    1: bug "Returning to usermode but unexpected PSR bits set?", \@
    
    right at the backslash.  (The line is part of a macro definition.)
    The next input buffer then starts with '@' which starts a comment on
    ARM, and the check for \@ fails due to to == tostart.  Now it would be
    possible to simply access to[-1] in this particular case, but that's
    ugly, and to be absolutely safe from people deliberately trying to
    crash gas we'd need the read.c:read_a_source_file buffer passed to
    do_scrub_chars to have a single byte pad at the start.
    
    	PR 22714
    	* app.c (last_char): New static var.
    	(struct app_save): Add last_char field.
    	(app_push, app_pop): Handle it.
    	(do_scrub_chars): Use last_char in test for "\@".  Set last_char.
Comment 2 Alan Modra 2018-01-31 06:36:50 UTC
Fixed