Bug 27252 - nm doesn't recognize null device on MS-Windows
Summary: nm doesn't recognize null device on MS-Windows
Status: RESOLVED NOTABUG
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.36
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-26 19:33 UTC by Eli Zaretskii
Modified: 2021-02-05 07:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch to recognize the null device on MS-Windows (639 bytes, patch)
2021-01-26 19:33 UTC, Eli Zaretskii
Details | Diff
A fixed patch (639 bytes, patch)
2021-01-26 20:11 UTC, Eli Zaretskii
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eli Zaretskii 2021-01-26 19:33:16 UTC
Created attachment 13161 [details]
Patch to recognize the null device on MS-Windows

On Unix, if you type "nm -B /dev/null", you get a nice warning:

       nm: Warning: '/dev/null' is not an ordinary file

But on Windows no such warning happens, and 'nm' behaves as if the null device were a regular file of zero size.  This is because the MS-Windows implementation of 'stat' doesn't report the null device as a character-special file, it reports it as a regular file.

The attached file fixes this problem, and a similar problem in 'elfedit'.
Comment 1 Eli Zaretskii 2021-01-26 20:11:15 UTC
Created attachment 13162 [details]
A fixed patch

Sorry, the original patch had a silly mistake; please use this on instead.
Comment 2 Sourceware Commits 2021-01-28 13:32:46 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit a7ad3cb1fff75e8e11df40128adda66a42a06239
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Thu Jan 28 13:32:05 2021 +0000

    Fix binutils tools so that they can cope with the special /dev/null file when run on Windows systems.
    
     PR 27252
     * bucomm.c (get_file_size): Add code to handle /dev/null on
     Windows systems.
     * elfedit.c (check_file): Likewise.
Comment 3 Nick Clifton 2021-01-28 13:33:30 UTC
Hi Eli,

  Thanks for the bug report and patch.  I have now applied it to the mainline sources.

Cheers
  Nick
Comment 4 Eli Zaretskii 2021-01-28 14:33:19 UTC
Now that I see the changeset in Git, I realize that the comments in my patch include a typo:

+      /* MS-Windows 'stat' doesn't reports the null device as a
+        regular file; fix that.  */

This should of course say

   MS-Windows 'stat' reports the null device as a regular file

(This mistake is in both comments.)

Sorry about that.
Comment 5 Sourceware Commits 2021-02-05 07:07:03 UTC
The master branch has been updated by Eli Zaretskii <eliz@sourceware.org>:

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

commit 887854bae4a3b7b1edc0b2f75a2781a8c31ba805
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Fri Feb 5 09:05:58 2021 +0200

    Fix typos in comments added in PR 27252 fix
    
            PR 27252
            * elfedit.c (check_file):
            * bucomm.c (get_file_size): Fix typos in comments.
Comment 6 Eli Zaretskii 2021-02-05 07:08:17 UTC
I took the liberty of fixing the typo in comments myself.
Hope this is okay.