<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/bugzilla.dtd">

<bugzilla version="4.0.10"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>14196</bug_id>
          
          <creation_ts>2012-06-04 10:08:00 +0000</creation_ts>
          <short_desc>gold mistreats -Wl,-Ttext</short_desc>
          <delta_ts>2013-01-02 02:42:17 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>binutils</product>
          <component>gold</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>ASSIGNED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Vladimir Serbinenko">phcoder</reporter>
          <assigned_to name="Ian Lance Taylor">ian</assigned_to>
          <cc>ccoutant</cc>
    
    <cc>cjwatson</cc>
    
    <cc>heiko</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <long_desc isprivate="0">
            <commentid>55553</commentid>
            <who name="Vladimir Serbinenko">phcoder</who>
            <bug_when>2012-06-04 10:08:11 +0000</bug_when>
            <thetext>Namely the minimal testcase is:
gcc -o 1.img -ffreestanding -Wl,-Ttext,0x8200 1.S -nostdlib -m32
The resulting file has .text at 9200 and not 8200
1.S:
.text

.globl _start
_start:

Because of this GRUB is miscompiled if attempting to link with gold</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>55556</commentid>
            <who name="Ian Lance Taylor">ian</who>
            <bug_when>2012-06-04 15:21:16 +0000</bug_when>
            <thetext>As I explained in e-mail, for gold the -Ttext option sets the address of the text segment, not the .text section.  This is intentional.  When I try your test case, I get these section addresses, as reported by readelf -S:


  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            00008200 000200 000024 00   A  0   0  4
  [ 2] .text             PROGBITS        00008224 000224 000000 00  AX  0   0  4
  [ 3] .data             PROGBITS        00009000 001000 000000 00  WA  0   0  4
  [ 4] .bss              NOBITS          00009000 001000 000000 00  WA  0   0  4
  [ 5] .note.gnu.gold-ve NOTE            00000000 001000 00001c 00      0   0  4
  [ 6] .symtab           SYMTAB          00000000 00101c 000050 10      7   1  4
  [ 7] .strtab           STRTAB          00000000 00106c 000020 00      0   0  1
  [ 8] .shstrtab         STRTAB          00000000 00108c 000056 00      0   0  1

The text segment starts at 0x8200.  The .text section is not at 0x9200.  If I change the command to

gcc -o 1.img -ffreestanding -Wl,-Ttext,0x8200 ~/foo.s -nostdlib -m32 -v --save-temps -Wl,--build-id=none

then the .text section is the first section in the text segment, and both are at address 0x8200.

So as far as I can see everything works as intended, and works as you want.  You need to provide more information: the version of the linker that you are using, and the command line passed to the linker, which you can get by using gcc -v.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>55557</commentid>
            <who name="Vladimir Serbinenko">phcoder</who>
            <bug_when>2012-06-04 15:30:08 +0000</bug_when>
            <thetext>It looks like I need to retest. It was probably some old gold version.</thetext>
          </long_desc>
          <long_desc isprivate="0">
            <commentid>59285</commentid>
            <who name="Colin Watson">cjwatson</who>
            <bug_when>2013-01-02 02:42:17 +0000</bug_when>
            <thetext>Adding -Wl,-N more accurately reproduces the bug as seen by GRUB.

GNU gold (GNU Binutils for Ubuntu 2.23.1) 1.11

$ gcc -v -fuse-ld=gold -o 1.img -ffreestanding -Wl,-Ttext,0x8200 1.S -nostdlib -m32 -Wl,-N -Wl,--build-id=none
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion=&apos;Ubuntu/Linaro 4.7.2-16ubuntu1&apos; --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-16ubuntu1)
COLLECT_GCC_OPTIONS=&apos;-v&apos; &apos;-fuse-ld=gold&apos; &apos;-o&apos; &apos;1.img&apos; &apos;-ffreestanding&apos; &apos;-nostdlib&apos; &apos;-m32&apos; &apos;-mtune=generic&apos; &apos;-march=i686&apos;
 /usr/lib/gcc/i686-linux-gnu/4.7/cc1 -E -lang-asm -quiet -v -imultilib . -imultiarch i386-linux-gnu 1.S -m32 -mtune=generic -march=i686 -fuse-ld=gold -ffreestanding -fno-directives-only -o /tmp/cc6TeMd1.s
ignoring nonexistent directory &quot;/usr/local/include/i386-linux-gnu&quot;
ignoring nonexistent directory &quot;/usr/lib/gcc/i686-linux-gnu/4.7/../../../../i686-linux-gnu/include&quot;
#include &quot;...&quot; search starts here:
#include &lt;...&gt; search starts here:
 /usr/lib/gcc/i686-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.7/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS=&apos;-v&apos; &apos;-fuse-ld=gold&apos; &apos;-o&apos; &apos;1.img&apos; &apos;-ffreestanding&apos; &apos;-nostdlib&apos; &apos;-m32&apos; &apos;-mtune=generic&apos; &apos;-march=i686&apos;
 as -v --32 -o /tmp/ccHEpBci.o /tmp/cc6TeMd1.s
GNU assembler version 2.23.1 (i686-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.23.1
COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS=&apos;-v&apos; &apos;-fuse-ld=gold&apos; &apos;-o&apos; &apos;1.img&apos; &apos;-ffreestanding&apos; &apos;-nostdlib&apos; &apos;-m32&apos; &apos;-mtune=generic&apos; &apos;-march=i686&apos;
 /usr/lib/gcc/i686-linux-gnu/4.7/collect2 --sysroot=/ --build-id --eh-frame-hdr -m elf_i386 --hash-style=gnu --as-needed -dynamic-linker /lib/ld-linux.so.2 -z relro -fuse-ld=gold -o 1.img -L/usr/lib/gcc/i686-linux-gnu/4.7 -L/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.7/../../.. -Ttext 0x8200 /tmp/ccHEpBci.o -N --build-id=none

$ readelf -S 1.img                                        There are 8 section headers, starting at offset 0x10d0:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00009000 001000 000000 00  AX  0   0  4
  [ 2] .data             PROGBITS        00009000 001000 000000 00  WA  0   0  4
  [ 3] .bss              NOBITS          00009000 001000 000000 00  WA  0   0  4
  [ 4] .note.gnu.gold-ve NOTE            00000000 001000 00001c 00      0   0  4
  [ 5] .symtab           SYMTAB          00000000 00101c 000050 10      6   1  4
  [ 6] .strtab           STRTAB          00000000 00106c 000020 00      0   0  1
  [ 7] .shstrtab         STRTAB          00000000 00108c 000043 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

GNU ld appears to optimise away the .text section, but if I add a &quot;nop&quot; to avoid that, it correctly starts .text at 00008200 with these options.</thetext>
          </long_desc>
      
      

    </bug>

</bugzilla>