Bug 10199 - 'nm' compiled for Linux -> Windows cross compilation silently ignores -S switch
Summary: 'nm' compiled for Linux -> Windows cross compilation silently ignores -S switch
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-26 06:57 UTC by Sergei Steshenko
Modified: 2009-06-01 01:51 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-mingw32msvc
Build: i686-pc-linux-gnu
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Steshenko 2009-05-26 06:57:51 UTC
I have an environment for cross compilation and cross Linking for Windows under
Linux, the environment was built using

http://www.profv.de/mingw_cross_env/README.html ->
http://www.profv.de/mingw_cross_env/mingw_cross_env-2.5.tar.gz
.

It works good enough for me producing working Windows console executables.

The following session shows the problem reported in the summary - '-S' switche
is silently ignored by 'nm'; as 'objdump' shows, the .o files are practically
equivalent, so if '-S' works with Linux .o file, it should also work with
Windows one.

The session:

sergei@amdam2:~/try_ltdl> cat -n f.c
     1  unsigned lib_function(double input)
     2    {
     3    return (unsigned)input;
     4    }
sergei@amdam2:~/try_ltdl> gcc -c f.c -o f.lin.o
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-nm -S f.lin.o
00000000 00000033 T lib_function
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-gcc -c f.c -o f.win.o
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-nm -S f.win.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 T _lib_function
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-objdump -S f.lin.o

f.lin.o:     file format elf32-i386


Disassembly of section .text:

00000000 <lib_function>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 18                sub    $0x18,%esp
   6:   8b 45 08                mov    0x8(%ebp),%eax
   9:   89 45 f8                mov    %eax,-0x8(%ebp)
   c:   8b 45 0c                mov    0xc(%ebp),%eax
   f:   89 45 fc                mov    %eax,-0x4(%ebp)
  12:   dd 45 f8                fldl   -0x8(%ebp)
  15:   d9 7d f6                fnstcw -0xa(%ebp)
  18:   0f b7 45 f6             movzwl -0xa(%ebp),%eax
  1c:   b4 0c                   mov    $0xc,%ah
  1e:   66 89 45 f4             mov    %ax,-0xc(%ebp)
  22:   d9 6d f4                fldcw  -0xc(%ebp)
  25:   df 7d e8                fistpll -0x18(%ebp)
  28:   d9 6d f6                fldcw  -0xa(%ebp)
  2b:   8b 45 e8                mov    -0x18(%ebp),%eax
  2e:   8b 55 ec                mov    -0x14(%ebp),%edx
  31:   c9                      leave
  32:   c3                      ret
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-objdump -S f.win.o

f.win.o:     file format pe-i386


Disassembly of section .text:

00000000 <_lib_function>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 18                sub    $0x18,%esp
   6:   8b 45 08                mov    0x8(%ebp),%eax
   9:   89 45 f8                mov    %eax,-0x8(%ebp)
   c:   8b 45 0c                mov    0xc(%ebp),%eax
   f:   89 45 fc                mov    %eax,-0x4(%ebp)
  12:   dd 45 f8                fldl   -0x8(%ebp)
  15:   d9 7d f6                fnstcw -0xa(%ebp)
  18:   0f b7 45 f6             movzwl -0xa(%ebp),%eax
  1c:   b4 0c                   mov    $0xc,%ah
  1e:   66 89 45 f4             mov    %ax,-0xc(%ebp)
  22:   d9 6d f4                fldcw  -0xc(%ebp)
  25:   df 7d e8                fistpll -0x18(%ebp)
  28:   d9 6d f6                fldcw  -0xa(%ebp)
  2b:   8b 45 e8                mov    -0x18(%ebp),%eax
  2e:   8b 55 ec                mov    -0x14(%ebp),%edx
  31:   c9                      leave
  32:   c3                      ret
  33:   90                      nop
sergei@amdam2:~/try_ltdl>
Comment 1 H.J. Lu 2009-05-29 05:25:51 UTC
Linux uses ELF which provides symbol size. You can use
"readelf -s" to see it. I don't think Windows has symbol
size info.
Comment 2 Sergei Steshenko 2009-05-29 05:54:51 UTC
I think you are missing a number of points - look, for example, at the following:

"
sergei@amdam2:~/try_ltdl> cat f.c
unsigned lib_function1(double input)
  {
  return (unsigned)input;
  }

inline void end1()
  {
  }
unsigned lib_function2(double input)
  {
  return (unsigned)input;
  }

inline void end2()
  {
  }
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-gcc -c f.c
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-nm f.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000033 T _end1
0000006b T _end2
00000000 T _lib_function1
00000038 T _lib_function2
sergei@amdam2:~/try_ltdl> ~/mingwi686/bin/i686-mingw32msvc-objdump -S f.o

f.o:     file format pe-i386


Disassembly of section .text:

00000000 <_lib_function1>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 18                sub    $0x18,%esp
   6:   8b 45 08                mov    0x8(%ebp),%eax
   9:   89 45 f8                mov    %eax,-0x8(%ebp)
   c:   8b 45 0c                mov    0xc(%ebp),%eax
   f:   89 45 fc                mov    %eax,-0x4(%ebp)
  12:   dd 45 f8                fldl   -0x8(%ebp)
  15:   d9 7d f6                fnstcw -0xa(%ebp)
  18:   0f b7 45 f6             movzwl -0xa(%ebp),%eax
  1c:   b4 0c                   mov    $0xc,%ah
  1e:   66 89 45 f4             mov    %ax,-0xc(%ebp)
  22:   d9 6d f4                fldcw  -0xc(%ebp)
  25:   df 7d e8                fistpll -0x18(%ebp)
  28:   d9 6d f6                fldcw  -0xa(%ebp)
  2b:   8b 45 e8                mov    -0x18(%ebp),%eax
  2e:   8b 55 ec                mov    -0x14(%ebp),%edx
  31:   c9                      leave
  32:   c3                      ret

00000033 <_end1>:
  33:   55                      push   %ebp
  34:   89 e5                   mov    %esp,%ebp
  36:   5d                      pop    %ebp
  37:   c3                      ret

00000038 <_lib_function2>:
  38:   55                      push   %ebp
  39:   89 e5                   mov    %esp,%ebp
  3b:   83 ec 18                sub    $0x18,%esp
  3e:   8b 45 08                mov    0x8(%ebp),%eax
  41:   89 45 f8                mov    %eax,-0x8(%ebp)
  44:   8b 45 0c                mov    0xc(%ebp),%eax
  47:   89 45 fc                mov    %eax,-0x4(%ebp)
  4a:   dd 45 f8                fldl   -0x8(%ebp)
  4d:   d9 7d f6                fnstcw -0xa(%ebp)
  50:   0f b7 45 f6             movzwl -0xa(%ebp),%eax
  54:   b4 0c                   mov    $0xc,%ah
  56:   66 89 45 f4             mov    %ax,-0xc(%ebp)
  5a:   d9 6d f4                fldcw  -0xc(%ebp)
  5d:   df 7d e8                fistpll -0x18(%ebp)
  60:   d9 6d f6                fldcw  -0xa(%ebp)
  63:   8b 45 e8                mov    -0x18(%ebp),%eax
  66:   8b 55 ec                mov    -0x14(%ebp),%edx
  69:   c9                      leave
  6a:   c3                      ret

0000006b <_end2>:
  6b:   55                      push   %ebp
  6c:   89 e5                   mov    %esp,%ebp
  6e:   5d                      pop    %ebp
  6f:   c3                      ret
sergei@amdam2:~/try_ltdl>    
"

- both 'nm' and 'objdump' show (relative) addresses of

_lib_function1
_end1
_lib_function2
_end2
.

Each of the above symbols lengths is

next_symbol_address - this_symbol_address

, where next_symbol_address is either true next_symbol_address or the last seen
in disassembly address plus one - the latter is for the last symbol in any section.

So, using the above definition I wrote for myself a Perl script (can publish it
here  if you are interested) which calculates symbol lengths according to the
above definition.

I' trying to say that symbol length information is there by definition -
otherwise linker wouldn't be able to correctly work, it will make mistakes and
overlap symbol areas, and the issue is properly extracting it.

I.e. even if certain object file format does not present symbol length info
readily available, it can easily be calculated.

And even if you are not going to implement the functionality, you couldn't have
closed the bug as WHATEVER INVALID - the bug _is_ _valid_ because I as end user
requested an action, and the request has been _silently_ ignored, and the word
"silently" is part of the summary.

I.e. if -S switch exists, and the manual says symbol lengths should be
displayed, then the lengths should either be displayed, or at least a warning
saying something like "symbol lengths for this input format are not supported"
should be issued.

Let me make it even more clear: this is a classical case of advertised behavior
(the manual promising symbol sizes in case of -S) is different from actual
behavior (symbol lengths are _not_ displayed), and thus is a _valid_ bug.
Comment 3 Sourceware Commits 2009-06-01 01:50:59 UTC
Subject: Bug 10199

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-06-01 01:50:45

Modified files:
	binutils       : ChangeLog 
	binutils/doc   : binutils.texi 

Log message:
	PR 10199
	* doc/binutils.texi (nm): Correct -S description.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/ChangeLog.diff?cvsroot=src&r1=1.1475&r2=1.1476
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/binutils/doc/binutils.texi.diff?cvsroot=src&r1=1.146&r2=1.147

Comment 4 Alan Modra 2009-06-01 01:51:49 UTC
Fixed.