@@ -4611,16 +4611,6 @@ static int _labels_compare(const void *a, const void *b) {
4611
4611
const struct label * l1 = a ;
4612
4612
const struct label * l2 = b ;
4613
4613
4614
- if (l1 -> section_status == OFF && l2 -> section_status == ON )
4615
- return 1 ;
4616
- if (l1 -> section_status == ON && l2 -> section_status == OFF )
4617
- return -1 ;
4618
-
4619
- if (l1 -> section > l2 -> section )
4620
- return 1 ;
4621
- else if (l1 -> section < l2 -> section )
4622
- return -1 ;
4623
-
4624
4614
if (l1 -> rom_address > l2 -> rom_address )
4625
4615
return 1 ;
4626
4616
else if (l1 -> rom_address < l2 -> rom_address )
@@ -4933,15 +4923,31 @@ int generate_sizeof_label_definitions(void) {
4933
4923
}
4934
4924
4935
4925
if (ls == NULL ) {
4936
- if (j == labelsN - 1 || labels [j ]-> section != labels [j + 1 ]-> section ) {
4937
- /* last label in this section */
4938
- if (labels [j ]-> section_struct != NULL )
4926
+ if (labels [j ]-> section_struct != NULL ) {
4927
+ /* inside a .SECTION, there are no holes in .SECTIONs so use labels to calculate the size */
4928
+ if (j == labelsN - 1 || labels [j ]-> section != labels [j + 1 ]-> section ) {
4929
+ /* last label in this .SECTION */
4939
4930
size = labels [j ]-> section_struct -> size - labels [j ]-> address_in_section ;
4931
+ }
4940
4932
else
4941
- continue ;
4933
+ size = ( int ) labels [ j + 1 ] -> rom_address - ( int ) labels [ j ] -> rom_address ;
4942
4934
}
4943
4935
else {
4944
- size = (int )labels [j + 1 ]-> rom_address - (int )labels [j ]-> rom_address ;
4936
+ /* find the size by examining g_rom_usage */
4937
+ int absolute_end , i ;
4938
+
4939
+ if (j == labelsN - 1 )
4940
+ absolute_end = g_romsize ;
4941
+ else
4942
+ absolute_end = (int )labels [j + 1 ]-> rom_address ;
4943
+
4944
+ /* find the next unused byte or encounter absolute_end */
4945
+ for (i = (int )labels [j ]-> rom_address ; i < absolute_end ; i ++ ) {
4946
+ if (g_rom_usage [i ] == 0 )
4947
+ break ;
4948
+ }
4949
+
4950
+ size = i - (int )labels [j ]-> rom_address ;
4945
4951
}
4946
4952
}
4947
4953
0 commit comments