Bump date stamp to 20130330
[official-gcc.git] / libgupc / gen-upc-ld-script.pl
blob26bbd92662cda73defbc301a1a6b78d9bdcec5a5
1 #!/usr/bin/perl -w
3 # Define linkage sections required by GUPC by editing
4 # the default GNU ld script.
6 use strict;
7 my $before_ctors = <<EOD;
8 .upc_alloc_array :
10 PROVIDE (__upc_alloc_array_start = .);
11 KEEP (*(SORT(upc_alloc_array.*)))
12 KEEP (*(upc_alloc_array))
13 PROVIDE (__upc_alloc_array_end = .);
15 .upc_alloc : { KEEP(*(upc_alloc)) }
16 .upc_init_array :
18 PROVIDE (__upc_init_array_start = .);
19 KEEP (*(SORT(upc_init_array.*)))
20 KEEP (*(upc_init_array))
21 PROVIDE (__upc_init_array_end = .);
23 .upc_init : { KEEP(*(upc_init)) }
24 /* UPC Program Info - compilation-related data */
25 .upc_pgm_info :
27 PROVIDE (__upc_pgm_info_start = .);
28 KEEP (*(upc_pgm_info));
29 PROVIDE (__upc_pgm_info_end = .);
31 EOD
32 my $after_end_dot = <<EOD;
33 /* UPC shared section - used to layout shared data only */
34 .upc_shared 0x4000 (NOLOAD):
36 PROVIDE (__upc_shared_start = .);
37 *(upc_shared);
38 PROVIDE (__upc_shared_end = .);
40 EOD
41 my $ld_script = do {local $/ = undef; <>};
42 for ($ld_script)
44 m{^GNU ld} or die "Not a GNU ld script?";
45 my $is_ia64 = /OUTPUT_ARCH\s*\(\s*ia64\s*\)/s;
46 if ($is_ia64)
48 # The linker on the IA64 (SuSE) can't handle the
49 # additional "nolaod" attribute. Drop it.
50 $after_end_dot =~ s/\s*\(NOLOAD\)//s;
52 s/^.*?\n=+\n//s;
53 s/\n(?:\s*\n)*=+\n.*$/\n/s;
54 s/^(.*\n)(\s*\.ctors.*?\n)/$1$before_ctors$2/s
55 or die "No match on .ctors line";
56 m{(\n\s*\.\s*\=\s*ALIGN\s*\(\s*\d+\s*/\s*8\s*\)\s*;[^\n]*\n)}s;
57 my $align = defined($1) ? "$1" : '';
58 s{\n((?:\s*\.\s*\=\s*ALIGN\s*\(\s*\d+\s*/\s*\d+\s*\)\s*;[^\n]*\n)*?
59 \s*_end\s*=\s*\.\s*;
60 \s*PROVIDE\s*\(\s*end\s*=\s*\.\s*\)\s*;[^\n]*\n
61 (?:\s*\.\s*\=\s*DATA_SEGMENT_END\s*\(\s*\.\s*\)\s*;[^\n]*\n)?)}
62 {$1$after_end_dot}sx
63 or die "No match on '_end = .;' line";
65 print $ld_script;