Bug 44812 - m32 lto produces non-relocatable subtraction expression errors
Summary: m32 lto produces non-relocatable subtraction expression errors
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-04 15:17 UTC by Jack Howarth
Modified: 2010-09-03 23:36 UTC (History)
5 users (show)

See Also:
Host: *86*-apple-darwin10
Target: *86*-apple-darwin10
Build: *86*-apple-darwin10
Known to work:
Known to fail:
Last reconfirmed:


Attachments
assembly file 20081111_0.s (2.25 KB, text/plain)
2010-07-04 15:23 UTC, Jack Howarth
Details
assembly file 20081111_1.s (1.65 KB, text/plain)
2010-07-04 15:24 UTC, Jack Howarth
Details
assembly file gcc-dg-lto-20081111-01.ltrans0.s (445 bytes, text/plain)
2010-07-04 15:25 UTC, Jack Howarth
Details
patch to effectively mark symbol as weak_import (283 bytes, patch)
2010-08-26 01:40 UTC, Jack Howarth
Details | Diff
patch which completely eliminates -m32 darwin lto failures (520 bytes, patch)
2010-08-27 00:42 UTC, Jack Howarth
Details | Diff
m32 darwin lto fix using external (546 bytes, text/plain)
2010-08-27 13:54 UTC, Jack Howarth
Details
corrected m32 darwin lto fix using external (533 bytes, text/plain)
2010-08-27 14:13 UTC, Jack Howarth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2010-07-04 15:17:07 UTC
On x86_64-apple-darwin* and i*86-apple-darwin*, a number of lto failures remain at -m32 which are of the form...

/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ c_lto_20081111_0.o c_lto_20081111_1.o -O0 -fwhopr -m32 -o gcc-dg-lto-20081111-01
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:15:non-relocatable subtraction expression, "_mumble" minus "L00000000001$pb"
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:15:symbol: "_mumble" can't be undefined in a subtraction expression
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:13:non-relocatable subtraction expression, "_mumble" minus "L00000000001$pb"
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:13:symbol: "_mumble" can't be undefined in a subtraction expression
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:10:non-relocatable subtraction expression, "_mumble" minus "L00000000001$pb"
/var/folders/1C/1CdoNxmNFHyOIjNBLNuJh++++TM/-Tmp-//ccogqVKS.s:10:symbol: "_mumble" can't be undefined in a subtraction expression
lto-wrapper: /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc returned 1 exit status
Comment 1 Jack Howarth 2010-07-04 15:23:36 UTC
Created attachment 21082 [details]
assembly file 20081111_0.s

/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ -O0 -fwhopr --save-temps -c -m32 -o c_lto_20081111_0.o /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100703/gcc/testsuite/gcc.dg/lto/20081111_0.c
Comment 2 Jack Howarth 2010-07-04 15:24:15 UTC
Created attachment 21084 [details]
assembly file 20081111_1.s

/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ -O0 -fwhopr -c -m32 --save-temps -o c_lto_20081111_1.o /sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100703/gcc/testsuite/gcc.dg/lto/20081111_1.c
Comment 3 Jack Howarth 2010-07-04 15:25:14 UTC
Created attachment 21085 [details]
assembly file gcc-dg-lto-20081111-01.ltrans0.s

/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/xgcc -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/ c_lto_20081111_0.o c_lto_20081111_1.o -O0 -fwhopr --save-temps -m32 -o gcc-dg-lto-20081111-01
Comment 4 Jack Howarth 2010-07-15 13:19:50 UTC
At -m32 on x86_64-apple-darwin10, the test cases which fail due to symbols being optimized away include...

FAIL: g++.dg/lto/20081118-1 cp_lto_20081118-1_0.o-cp_lto_20081118-1_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20081119-1 cp_lto_20081119-1_0.o-cp_lto_20081119-1_1.o link, -fPIC -fwhopr -r -nostdlib
FAIL: g++.dg/lto/20081125 cp_lto_20081125_0.o-cp_lto_20081125_1.o link, -fwhopr
FAIL: g++.dg/lto/20081209 cp_lto_20081209_0.o-cp_lto_20081209_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20081209 cp_lto_20081209_0.o-cp_lto_20081209_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20081211-1 cp_lto_20081211-1_0.o-cp_lto_20081211-1_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20081211-1 cp_lto_20081211-1_0.o-cp_lto_20081211-1_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20090302 cp_lto_20090302_0.o-cp_lto_20090302_1.o link, -fPIC -fwhopr -r -nostdlib
FAIL: g++.dg/lto/20090311-1 cp_lto_20090311-1_0.o-cp_lto_20090311-1_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20090311-1 cp_lto_20090311-1_0.o-cp_lto_20090311-1_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20090311 cp_lto_20090311_0.o-cp_lto_20090311_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20090312 cp_lto_20090312_0.o-cp_lto_20090312_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20090312 cp_lto_20090312_0.o-cp_lto_20090312_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20090315 cp_lto_20090315_0.o-cp_lto_20090315_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20090315 cp_lto_20090315_0.o-cp_lto_20090315_1.o link, -O2 -fwhopr
FAIL: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o link, -O0 -fwhopr
FAIL: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o link, -O2 -fwhopr
FAIL: g++.dg/torture/pr43879-1_1.C  -O2 -fwhopr  (test for excess errors)
FAIL: gcc.dg/lto/20081111 c_lto_20081111_0.o-c_lto_20081111_1.o link, -O0 -fwhopr
FAIL: gcc.dg/lto/20081111 c_lto_20081111_0.o-c_lto_20081111_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20081112 c_lto_20081112_0.o-c_lto_20081112_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20090717 c_lto_20090717_0.o-c_lto_20090717_1.o link, -O0 -fwhopr
FAIL: gcc.dg/lto/20090717 c_lto_20090717_0.o-c_lto_20090717_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20091005-1 c_lto_20091005-1_0.o-c_lto_20091005-1_1.o link, -O0 -fwhopr
FAIL: gcc.dg/lto/20100227-1 c_lto_20100227-1_0.o-c_lto_20100227-1_1.o link, -O0 -fwhopr
FAIL: gcc.dg/lto/20100227-1 c_lto_20100227-1_0.o-c_lto_20100227-1_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/ipacp c_lto_ipacp_0.o-c_lto_ipacp_1.o link,  -O1 -fwhopr -fipa-cp -fipa-cp-clone
FAIL: gcc.dg/lto/ipareference2 c_lto_ipareference2_0.o-c_lto_ipareference2_1.o link,  -O1 -fwhopr -fwhole-program
FAIL: gcc.dg/lto/materialize-1 c_lto_materialize-1_0.o-c_lto_materialize-1_1.o link,  -O3 -fwhopr
FAIL: gcc.dg/torture/pr43879_1.c  -O2 -fwhopr  (test for excess errors)

...which represents almost the entirety of the lto related failures at -m32 on darwin.
Comment 5 Jan Hubicka 2010-08-24 13:01:21 UTC
Hmm, the problem seems to be that partitioning puts mumble into one partition, while in first partition it uses local (IP) relative way to access it:
movl    _mumble-L00000000001$pb(%ebx), %eax
and assembler refuse it.  What is proper way to access hidden symbol from other .s file?
Comment 6 Dominique d'Humieres 2010-08-24 13:17:46 UTC
The same errors appear on powerpc-apple-darwin9 with both -m32 and -m64 (see http://gcc.gnu.org/ml/gcc-testresults/2010-08/msg00777.html ).
Comment 7 Jack Howarth 2010-08-24 13:44:04 UTC
(In reply to comment #5)
> Hmm, the problem seems to be that partitioning puts mumble into one partition,
> while in first partition it uses local (IP) relative way to access it:
> movl    _mumble-L00000000001$pb(%ebx), %eax
> and assembler refuse it.  What is proper way to access hidden symbol from other
> .s file?
> 

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43729#c33
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43729#c37
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43729#c42

Comment 8 Jan Hubicka 2010-08-24 13:44:33 UTC
the following testcase:
__attribute__((visibility ("hidden"))) extern int mumble;
extern void abort (void);
extern void exit (int);

int
main ()
{
  if (++mumble != 42)
    abort ();
  exit (0);
}

should compile to pretty much the same as the partition. We get:
        call    ___i686.get_pc_thunk.bx
L00000000001$pb:
        subl    $24, %esp
LCFI1:
        movl    L_mumble$non_lazy_ptr-L00000000001$pb(%ebx), %edx
        movl    (%edx), %eax
        addl    $1, %eax
        cmpl    $42, %eax
        movl    %eax, (%edx)
        je      L2
        call    _abort

and later
L_mumble$non_lazy_ptr:
        .long   _mumble

while in the partitoin we get:
CFI1:  
        movl    _mumble-L00000000001$pb(%ebx), %eax
        addl    $1, %eax
        cmpl    $42, %eax
        movl    %eax, _mumble-L00000000001$pb(%ebx)
        je      L2
        call    _abort
L2:
        movl    $0, (%esp)
        call    _exit
LFE0:   

and no later mention of it...
Comment 9 Iain Sandoe 2010-08-24 13:47:13 UTC
(In reply to comment #5)
> Hmm, the problem seems to be that partitioning puts mumble into one partition,
> while in first partition it uses local (IP) relative way to access it:
> movl    _mumble-L00000000001$pb(%ebx), %eax
> and assembler refuse it.  What is proper way to access hidden symbol from other
> .s file?

Take a look at the output of compilation without lto .. 
.. the symbol is indirected - since it cannot be guaranteed to be within reach otherwise;

so (by convention) 
_mumble-L00000000001$pb   => L__mumble$non_lazy_ptr-L00000000001$pb

......

        .non_lazy_symbol_pointer
L_mumble$non_lazy_ptr:
        .indirect_symbol _mumble
        .long   0
Comment 10 Iain Sandoe 2010-08-24 14:11:05 UTC
(In reply to comment #9)
> (In reply to comment #5)
> > Hmm, the problem seems to be that partitioning puts mumble into one partition,
> > while in first partition it uses local (IP) relative way to access it:
> > movl    _mumble-L00000000001$pb(%ebx), %eax
> > and assembler refuse it.  What is proper way to access hidden symbol from other
> > .s file?
> 
> Take a look at the output of compilation without lto .. 
> .. the symbol is indirected - since it cannot be guaranteed to be within reach
> otherwise;
>

which you already posted,
I don't think the hidden attribute is relevant, looking at other fails.

local symbols need to be registered with machopic_define_symbol() 
(see config/darwin.h ASM_DECLARE_OBJECT_NAME).

they are processed via machopic_finish() called from darwin_file_end () [config/darwin.c] 
which , I assume is still called in the lto case?

Comment 11 Iain Sandoe 2010-08-24 14:37:35 UTC
essentially to turn the last comment around:

IIUC, if whopr changes a symbol from "external" to "local"  then it needs to register that symbol with machopic_define_symbol () -- and ensure that  (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false); gets called too.. 
Comment 12 Jan Hubicka 2010-08-24 15:04:50 UTC
Subject: Re:  m32 lto produces non-relocatable subtraction
	expression errors

Hmm, actually the symbol is not changed, since it is externally visible symbol.
I guess the problem would be that the symbol is used by 2 units, so both of
them gets the declaration, but both of them gets the declaration with
initializer (not extern).  To avoid duplicate definitions, varpool.c is testing
in_other_partition and prevents calling assemble_variable on them. This works
just fine on ELF since extern vars don't need to be announced.  Here we
apparently need to get it assembled, but it is not getting via
assemble_external.

Rebuilding the decl to DECL_EXTERN is probably possible, but somewhat hackish.

Honza
Comment 13 Iain Sandoe 2010-08-24 15:17:40 UTC
(In reply to comment #12)
> Subject: Re:  m32 lto produces non-relocatable subtraction
>         expression errors
> 
> Hmm, actually the symbol is not changed, since it is externally visible symbol.

ah, OK.

> assemble_external ().

is a no-op on darwin (unless the symbol is weak).
since we don't declare ASM_OUTPUT_EXTERNAL.

There might be some trick with marking the symbols weak/weak_import but I know nothing of the internals of lto to comment further.

Comment 14 Jack Howarth 2010-08-24 15:40:15 UTC
What about Mike's suggestions from Comment 33 of PR43729 ...

"If one bundles all the code into the wpa file, one can preserve
_good_ codegen, which is the other way to fix this."
Comment 15 Jack Howarth 2010-08-26 01:40:36 UTC
Created attachment 21567 [details]
patch to effectively mark symbol as weak_import
Comment 16 Jack Howarth 2010-08-26 01:55:01 UTC
Marking the symbols in_other_partitions as weak eliminates almost all of the failures. I still get...

Running target unix/-m32
FAIL: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o link, -O2 -fwhopr
UNRESOLVED: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o execute -O2 -fwhopr
FAIL: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o link, -O2 -fwhopr
UNRESOLVED: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o execute -O2 -fwhopr

 which still have the "non-relocatable subtraction expression"..."can't be undefined in a subtraction expression" errors. This might suggest the same problem exists somewhere else in varpool.c.
Comment 17 Jack Howarth 2010-08-26 10:18:54 UTC
Testresults with proposed patch at http://gcc.gnu.org/ml/gcc-testresults/2010-08/msg02586.html.
Comment 18 Jack Howarth 2010-08-26 16:01:08 UTC
Jan's alternative patch...

Index: lto-cgraph.c
===================================================================
--- lto-cgraph.c        (revision 163494)
+++ lto-cgraph.c        (working copy)
@@ -1109,6 +1109,8 @@
   node->analyzed = node->finalized;
   node->used_from_other_partition = bp_unpack_value (&bp, 1);
   node->in_other_partition = bp_unpack_value (&bp, 1);
+  if (node->in_other_partition)
+    DECL_EXTERNAL (node->decl) = 1;
   aliases_p = bp_unpack_value (&bp, 1);
   if (node->finalized)
     varpool_mark_needed_node (node);

works only slightly worse than marking the symbols weak. This produces the failures...

Running target unix/-m32
FAIL: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o link, -O2 -fwhopr
UNRESOLVED: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o execute -O2 -fwhopr
FAIL: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o link, -O2 -fwhopr
UNRESOLVED: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o execute -O2 -fwhopr
FAIL: gcc.dg/lto/ipareference2 c_lto_ipareference2_0.o-c_lto_ipareference2_1.o execute  -O1 -fwhopr -fwhole-program

in the gcc testsuite. The last failure was suppressed in the previous case.
Comment 19 Dominique d'Humieres 2010-08-26 20:03:11 UTC
With the patch in comment #18, with -m64 I see the following failure

FAIL: gcc.dg/lto/ipareference2 c_lto_ipareference2_0.o-c_lto_ipareference2_1.o execute  -O1 -fwhopr -fwhole-program

which was only present with -m32 without the patch. Otherwise the patch fixes many failures for the gcc and g++ test suites.
Comment 20 Dominique d'Humieres 2010-08-27 00:09:24 UTC
The patch in comment #18 works also on powerpc-apple-darwin9:

Running target unix/-m32
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/gcc.dg/lto/lto.exp ...
FAIL: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/ipareference2 c_lto_ipareference2_0.o-c_lto_ipareference2_1.o execute  -O1 -fwhopr -fwhole-program

		=== gcc Summary for unix/-m32 ===

# of expected passes		613
# of unexpected failures	3
# of unresolved testcases	2
# of unsupported tests		8
Running target unix/-m64
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/gcc.dg/lto/lto.exp ...
FAIL: gcc.dg/lto/20090116 c_lto_20090116_0.o-c_lto_20090116_0.o link, -O1 -fwhopr -fPIC (internal compiler error)
FAIL: gcc.dg/lto/20090213 c_lto_20090213_0.o-c_lto_20090213_1.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/20090218 c_lto_20090218_0.o-c_lto_20090218_3.o link, -O2 -fwhopr
FAIL: gcc.dg/lto/ipareference2 c_lto_ipareference2_0.o-c_lto_ipareference2_1.o execute  -O1 -fwhopr -fwhole-program

		=== gcc Summary for unix/-m64 ===

# of expected passes		612
# of unexpected failures	4
# of unresolved testcases	3
# of unsupported tests		8

		=== gcc Summary ===

# of expected passes		1225
# of unexpected failures	7
# of unresolved testcases	5
# of unsupported tests		16
/opt/gcc/darwin_buildw/gcc/xgcc  version 4.6.0 20100825 (experimental) [trunk revision 163553p1] (GCC) 

with an extra ICE for gcc.dg/lto/20090116.
Comment 21 Jack Howarth 2010-08-27 00:42:39 UTC
Created attachment 21575 [details]
patch which completely eliminates -m32 darwin lto failures
Comment 22 Jack Howarth 2010-08-27 00:44:17 UTC
The m32_lto_fix2.diff patch expands the usage of DECL_WEAK into gcc/lto-cgraph.c and is sufficient to eliminate all of the darwin-specific lto failures at -m32. The only remaining ones are...


FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -flto (internal compiler error)
UNRESOLVED: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o execute -fcompare-debug -flto
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -fwhopr (internal compiler error)
UNRESOLVED: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o execute -fcompare-debug -fwhopr
Comment 23 Dominique d'Humieres 2010-08-27 10:30:37 UTC
With the patch in comment #21 I get for powerpc-apple-darwin9

Running target unix/-m32
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/gcc.dg/lto/lto.exp ...

		=== gcc Summary for unix/-m32 ===

# of expected passes		618
# of unsupported tests		8
Running target unix/-m64
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/gcc.dg/lto/lto.exp ...
FAIL: gcc.dg/lto/20090116 c_lto_20090116_0.o-c_lto_20090116_0.o link, -O1 -fwhopr -fPIC (internal compiler error)

		=== gcc Summary for unix/-m64 ===

# of expected passes		617
# of unexpected failures	1
# of unresolved testcases	1
# of unsupported tests		8

		=== gcc Summary ===

# of expected passes		1235
# of unexpected failures	1
# of unresolved testcases	1
# of unsupported tests		16
/opt/gcc/darwin_buildw/gcc/xgcc  version 4.6.0 20100825 (experimental) [trunk revision 163553p1b] (GCC) 

and

Running target unix/-m32
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/g++.dg/lto/lto.exp ...
FAIL: g++.dg/lto/20081109 cp_lto_20081109_0.o-cp_lto_20081109_1.o execute -O2 -fwhopr
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -flto (internal compiler error)
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -fwhopr (internal compiler error)

		=== g++ Summary for unix/-m32 ===

# of expected passes		459
# of unexpected failures	3
# of unresolved testcases	2
# of unsupported tests		1
Running target unix/-m64
Using /sw/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /sw/share/dejagnu/config/unix.exp as generic interface file for target.
Using /opt/gcc/gcc-4.6-work/gcc/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /opt/gcc/gcc-4.6-work/gcc/testsuite/g++.dg/lto/lto.exp ...
FAIL: g++.dg/lto/20081109 cp_lto_20081109_0.o-cp_lto_20081109_1.o execute -O2 -fwhopr
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -flto (internal compiler error)
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -fwhopr (internal compiler error)

		=== g++ Summary for unix/-m64 ===

# of expected passes		459
# of unexpected failures	3
# of unresolved testcases	2
# of unsupported tests		1

		=== g++ Summary ===

# of expected passes		918
# of unexpected failures	6
# of unresolved testcases	4
# of unsupported tests		2
/opt/gcc/darwin_buildw/gcc/testsuite/g++/../../g++  version 4.6.0 20100825 (experimental) [trunk revision 163553p1b] (GCC) 
Comment 24 Jack Howarth 2010-08-27 12:10:34 UTC
Testsuite results for m32_to_fix2.diff at http://gcc.gnu.org/ml/gcc-testresults/2010-08/msg02690.html.
This approach completely fixes the darwin-specific lto failures on x86_64-apple-darwin10.
Comment 25 Jack Howarth 2010-08-27 13:54:08 UTC
Created attachment 21577 [details]
m32 darwin lto fix using external
Comment 26 Jack Howarth 2010-08-27 13:59:29 UTC
(In reply to comment #25)
> Created an attachment (id=21577) [edit]
> m32 darwin lto fix using external
> 

This version almost works. However I get the following c++ lto failures...

FAIL: g++.dg/lto/20081022 cp_lto_20081022_0.o-cp_lto_20081022_1.o link, -O0 -fwhopr
UNRESOLVED: g++.dg/lto/20081022 cp_lto_20081022_0.o-cp_lto_20081022_1.o execute -O0 -fwhopr
FAIL: g++.dg/lto/20081125 cp_lto_20081125_0.o-cp_lto_20081125_1.o link, -fwhopr
UNRESOLVED: g++.dg/lto/20081125 cp_lto_20081125_0.o-cp_lto_20081125_1.o execute -fwhopr
FAIL: g++.dg/lto/20081203 cp_lto_20081203_0.o-cp_lto_20081203_1.o link, -O0 -fwhopr
UNRESOLVED: g++.dg/lto/20081203 cp_lto_20081203_0.o-cp_lto_20081203_1.o execute -O0 -fwhopr
FAIL: g++.dg/lto/20090311 cp_lto_20090311_0.o-cp_lto_20090311_1.o link, -O0 -fwhopr
UNRESOLVED: g++.dg/lto/20090311 cp_lto_20090311_0.o-cp_lto_20090311_1.o execute -O0 -fwhopr
FAIL: g++.dg/lto/20090311 cp_lto_20090311_0.o-cp_lto_20090311_1.o link, -O2 -fwhopr
UNRESOLVED: g++.dg/lto/20090311 cp_lto_20090311_0.o-cp_lto_20090311_1.o execute -O2 -fwhopr
FAIL: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o link, -O0 -fwhopr
UNRESOLVED: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o execute -O0 -fwhopr
FAIL: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o link, -O2 -fwhopr
UNRESOLVED: g++.dg/lto/20091210-1 cp_lto_20091210-1_0.o-cp_lto_20091210-1_1.o execute -O2 -fwhopr
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -flto (internal compiler error)
UNRESOLVED: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o execute -fcompare-debug -flto
FAIL: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o link, -fcompare-debug -fwhopr (internal compiler error)
UNRESOLVED: g++.dg/lto/20100723-1 cp_lto_20100723-1_0.o-cp_lto_20100723-1_0.o execute -fcompare-debug -fwhopr

Executing on host: /sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../g++ -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/gcc/testsuite/g++/../../ cp_lto_20081022_0.o cp_lto_20081022_1.o  -nostdinc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include/x86_64-apple-darwin10.5.0 -I/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/include -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100826/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100826/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc46-4.6.0-1000/gcc-4.6-20100826/libstdc++-v3/testsuite/util -fmessage-length=0 -O0 -fwhopr     -L/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/src/.libs  -B/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/src/.libs  -L/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libstdc++-v3/src/.libs -L/sw/src/fink.build/gcc46-4.6.0-1000/darwin_objdir/x86_64-apple-darwin10.5.0/i386/libiberty  -multiply_defined suppress     -m32 -o g++-dg-lto-20081022-01    (timeout = 300)
Undefined symbols:^M
  "__ZN3foo3barEv", referenced from:^M
      __Z1gP3foo in ccxsAxgO.ltrans0.ltrans.o^M
      __Z1fP3foo in ccxsAxgO.ltrans1.ltrans.o^M
ld: symbol(s) not found^M

On the positive side, all of the original non-relocatable subtraction expression
errors are gone.
Comment 27 Jack Howarth 2010-08-27 14:13:56 UTC
Created attachment 21578 [details]
corrected m32 darwin lto fix using external
Comment 28 Jack Howarth 2010-08-27 14:15:39 UTC
(In reply to comment #27)
> Created an attachment (id=21578) [edit]
> corrected m32 darwin lto fix using external
> 

My mistake. The additional assemble_external() calls weren't needed in lto-cgraph.c and this reduced patch produces the same errors. Any idea of what is happening to ltrans such that the symbols become undefined now?
Comment 29 Iain Sandoe 2010-08-27 17:38:09 UTC
(In reply to comment #12)
> Subject: Re:  m32 lto produces non-relocatable subtraction
>         expression errors
> 
> Hmm, actually the symbol is not changed, since it is externally visible symbol.
> I guess the problem would be that the symbol is used by 2 units, so both of
> them gets the declaration, but both of them gets the declaration with
> initializer (not extern).  To avoid duplicate definitions, varpool.c is testing
> in_other_partition and prevents calling assemble_variable on them. 

so one gets emitted and the other doesn't?

This works
> just fine on ELF since extern vars don't need to be announced.  

we don't need to announce them either ... (assemble_external() is a no-op).

Here we
> apparently need to get it assembled, but it is not getting via
> assemble_external.

we need to get the right entry into the machopic tables - if the var is local to the TU ... 
> 
> Rebuilding the decl to DECL_EXTERN is probably possible, but somewhat hackish.

I guess this is just allowing it to be assembled... 

===

It is possible that the following is the root of the problem; 

when deciding how to output a var darwin/macho-pic takes the presence of an initializer as evidence that the var is defined in the current TU and that, therefore, it can reference it locally and doesn't need to output the other stuff.  unless the var passes through assemble_var () this will not get done.

assemble_external () seems a bit hackish too...

I'm not clear why the two instances are not coalesced by the whopr process?
Is that to cater for file-scope vars?

Comment 30 Jack Howarth 2010-09-01 14:38:48 UTC
Original -m32 lto testsuite failures due to "non-relocatable subtraction expression" errors were made latent by the commit...

Author: ak
Date: Tue Aug 31 16:58:46 2010
New Revision: 163680

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163680
Log:

       * common.opt (fwhopr=): Update for -fwhopr=jobserver
       * doc/invoke.texi (fwhopr): Document -fwhopr=jobserver.
       * lto-wrapper.c (run_gcc): Add jobserver mode.
       * opts.c (common_handle_option): Fix OPT_fwhopr for non numeric
         argument.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/common.opt
    trunk/gcc/doc/invoke.texi
    trunk/gcc/lto-wrapper.c
    trunk/gcc/opts.c
Comment 31 Jan Hubicka 2010-09-01 14:42:02 UTC
Subject: Re:  m32 lto produces non-relocatable subtraction
	expression errors

> Original -m32 lto testsuite failures due to "non-relocatable subtraction
> expression" errors were made latent by the commit...

Hmm, this does not make much sense. What changed?
Honza
Comment 32 Jan Hubicka 2010-09-03 12:26:54 UTC
Subject: Bug 44812

Author: hubicka
Date: Fri Sep  3 12:26:24 2010
New Revision: 163811

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163811
Log:

	PR lto/44812
	* lto-cgraph.c (intput_node, input_varpool_node): Set DECL_EXTERNAL
	on functions/variables in other partition.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lto-cgraph.c

Comment 33 Jack Howarth 2010-09-03 23:36:54 UTC
Fixed at r163811.