blob: 29b5328c820bd34f4578fb66b157630f4f1c710f [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2006
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#*****************************************************************************
36#*
37#* Filename:
38#* ---------
39#* fix_nosyms_library.pl
40#*
41#* Project:
42#* --------
43#* MAUI
44#*
45#* Description:
46#* ------------
47#* This script will add a armlibc_rvct.obj into a library, armlibc_rvct.obj only
48#* has a single useless ____mtk_fix_empty_library_function_should_not_be_used_by_anybody
49#* Author:
50#* -------
51#* Shuguang Wen (mtk80458)
52#*
53#*============================================================================
54#* HISTORY
55#* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
56#*------------------------------------------------------------------------------
57#* $Revision$
58#* $Modtime$
59#* $Log$
60#*
61#* 08 16 2012 ying.xin
62#* [MOLY00002197] [gcc]newlib tailoring and performance optimization check in
63#* .
64#*
65#*
66#*------------------------------------------------------------------------------
67#* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
68#*============================================================================
69#****************************************************************************/
70#
71
72use warnings;
73use strict;
74
75sub generate_unused_object {
76 my $ARMCC = "armcc";
77 my $source = <<END;
78
79 #pragma arm section code="SHOULDBE_EMPTYSECTION"
80 void ____mtk_fix_empty_library_function_should_not_be_used_by_anybody(void)
81 {
82 return;
83 }
84
85END
86
87 open FH, ">", "armlibc_rvct.c" || die "Can't open armlibc_rvct.c for writing";
88 print FH $source;
89 close FH;
90
91 my $status = system($ARMCC, "-c", "-o", "armlibc_rvct.obj", "armlibc_rvct.c");
92 if ($status != 0) {
93 die "Can't compile armlibc_rvct.c";
94 }
95}
96
97sub usage {
98 print STDERR "usage: perl $0 {option}* {library path to be fix}+\n";
99 print STDERR "supported options:\n";
100 print STDERR " --force replace armlibc_rvct.obj in library unconditionally\n";
101}
102
103# a specicial function to search object file in a library
104if ($#ARGV >= 0 && $ARGV[0] eq "--search_object") {
105 my @objects = ();
106
107 shift @ARGV;
108 for (my $i = 0; $i <= $#ARGV; $i++) {
109 push @objects, $ARGV[$i];
110 }
111 exit 0 if $#objects == -1;
112
113 open FH, "<", "make/pcore/~sortedLibs.tmp" or die "can't find make/pcore/~sortedLibs.tmp";
114 my @words = map { chomp; split /\s+/; } <FH>;
115 close FH;
116
117 foreach my $f (@words) {
118 next if $f =~ /^-/;
119 next if not ($f =~ /\.lib$/ || $f =~ /\.a$/);
120 next if not -f $f;
121
122 open FH, "-|", "armar -t $f" or next;
123 my @objs_in_lib = map { chomp; split /\s+/; } <FH>;
124 close FH;
125 #print join("\n", @objs_in_lib);
126
127 foreach my $r (@objects) {
128 foreach my $o (@objs_in_lib) {
129 if (lc $r eq lc $o) {
130 print "found $r in $f\n";
131 last;
132 }
133 }
134 }
135 }
136 exit 0;
137}
138
139my $force_fix = 0;
140my @to_be_fix_libs = ();
141foreach (@ARGV) {
142 if ($_ eq "--force") {
143 $force_fix = 1;
144 }
145 else {
146 push @to_be_fix_libs, $_;
147 }
148}
149if ($#to_be_fix_libs < 0) {
150 print STDERR "No library need to be fix\n";
151 usage;
152 exit 1;
153}
154
155generate_unused_object;
156
157for my $lib (@to_be_fix_libs) {
158 if (not -f $lib) {
159 print "$lib: failed, can't find this library\n";
160 next;
161 }
162 open PIPE, "-|", "armar -t $lib";
163 my @lib_objs = map { chomp; split /\s+/; } <PIPE>;
164 close PIPE;
165 if ($? != 0) {
166 print "$lib: failed, can't use armar -t to extract contents\n";
167 next;
168 }
169 if (not $force_fix) {
170 my $has_it = grep { lc $_ eq "armlibc_rvct.obj" } @lib_objs;
171 if ($has_it) {
172 print "$lib: failed, already has armlibc_rvct.obj\n";
173 next;
174 }
175 }
176 my $status = system("armar", "-sr", "$lib", "armlibc_rvct.obj");
177 if ($status != 0) {
178 print "$lib: failed, can't add armlibc_rvct.obj into $lib\n";
179 next;
180 }
181 print "$lib: succeeded\n";
182}
183
184unlink "armlibc_rvct.c", "armlibc_rvct.obj";