11"use strict" ;
2- var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
3- function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
4- return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
5- function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
6- function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
7- function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
8- step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
9- } ) ;
10- } ;
112Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
123exports . HardwareCompilerJournal = exports . HardwareCompiler = void 0 ;
134const fs_1 = require ( "fs" ) ;
@@ -247,39 +238,35 @@ class HardwareCompiler {
247238 this . dynSymEntries . push ( { name : '' , type : STT_NOTYPE } ) ;
248239 }
249240 }
250- useLibrary ( name ) {
251- return __awaiter ( this , void 0 , void 0 , function * ( ) {
252- this . enableDynamicLinking ( ) ;
253- if ( name === 'libc' ) {
254- const soname = 'libc.so.6' ;
255- if ( ! this . neededLibraries . includes ( soname ) ) {
256- this . neededLibraries . push ( soname ) ;
257- }
258- }
259- else {
260- throw new Error ( `Lib ${ name } not supported` ) ;
241+ async useLibrary ( name ) {
242+ this . enableDynamicLinking ( ) ;
243+ if ( name === 'libc' ) {
244+ const soname = 'libc.so.6' ;
245+ if ( ! this . neededLibraries . includes ( soname ) ) {
246+ this . neededLibraries . push ( soname ) ;
261247 }
262- } ) ;
248+ }
249+ else {
250+ throw new Error ( `Lib ${ name } not supported` ) ;
251+ }
263252 }
264- requireSymbol ( name_1 , libPrefix_1 ) {
265- return __awaiter ( this , arguments , void 0 , function * ( name , libPrefix , type = STT_FUNC ) {
266- if ( libPrefix && libPrefix . toLowerCase ( ) !== 'libc' ) {
267- throw new Error ( `Lib prefix ${ libPrefix } not supported` ) ;
268- }
269- this . enableDynamicLinking ( ) ;
270- if ( ! this . neededLibraries . includes ( 'libc.so.6' ) ) {
271- yield this . useLibrary ( 'libc' ) ;
272- }
273- if ( this . dynamicSymbols . has ( name ) ) {
274- return ;
275- }
276- // Just add to lists, sizes handled by dedicated build functions
277- const symIndex = this . dynSymEntries . length ; // Calculate potential index position
278- this . dynSymEntries . push ( { name, type } ) ;
279- // Offsets calculated in buildFinalDynSymData based on final index
280- this . dynamicSymbols . set ( name , {
281- name, index : - 1 , pltOffset : undefined , gotOffset : undefined , type, binding : STB_GLOBAL
282- } ) ;
253+ async requireSymbol ( name , libPrefix , type = STT_FUNC ) {
254+ if ( libPrefix && libPrefix . toLowerCase ( ) !== 'libc' ) {
255+ throw new Error ( `Lib prefix ${ libPrefix } not supported` ) ;
256+ }
257+ this . enableDynamicLinking ( ) ;
258+ if ( ! this . neededLibraries . includes ( 'libc.so.6' ) ) {
259+ await this . useLibrary ( 'libc' ) ;
260+ }
261+ if ( this . dynamicSymbols . has ( name ) ) {
262+ return ;
263+ }
264+ // Just add to lists, sizes handled by dedicated build functions
265+ const symIndex = this . dynSymEntries . length ; // Calculate potential index position
266+ this . dynSymEntries . push ( { name, type } ) ;
267+ // Offsets calculated in buildFinalDynSymData based on final index
268+ this . dynamicSymbols . set ( name , {
269+ name, index : - 1 , pltOffset : undefined , gotOffset : undefined , type, binding : STB_GLOBAL
283270 } ) ;
284271 }
285272 //#endregion Library/Dynamic Linking Management
@@ -288,7 +275,7 @@ class HardwareCompiler {
288275 this . requireSection ( ".text" /* SectionName.TEXT */ ) ;
289276 this . internalEmitBytes ( ".text" /* SectionName.TEXT */ , buffer ) ; // Add the instruction bytes
290277 if ( reloc ) {
291- const copyRelocToPush = Object . assign ( { } , reloc ) ;
278+ const copyRelocToPush = { ... reloc } ;
292279 this . relocations . push ( copyRelocToPush ) ;
293280 }
294281 }
@@ -527,7 +514,6 @@ class HardwareCompiler {
527514 // Process symbols added by the user (like 'message_symbol')
528515 HardwareCompilerJournal . success ( 2 , `[buildFinalSymtabData] Starting local symbol loop (using forEach). Map size: ${ this . localSymbols . size } ` ) ;
529516 this . localSymbols . forEach ( ( sym , name ) => {
530- var _a , _b ;
531517 // Log every iteration start
532518 HardwareCompilerJournal . success ( 3 , ` [buildFinalSymtabData] FOREACH ITERATION: name='${ name } ', type=${ sym . type } , sectionName='${ sym . sectionName } ', index=${ sym . index } ` ) ;
533519 // Skip the SECTION symbols we just created in the loop above
@@ -560,8 +546,8 @@ class HardwareCompiler {
560546 entry . writeUInt8 ( ( STB_LOCAL << 4 ) | ( sym . type & 0xf ) , 4 ) ; // st_info: Binding=LOCAL, Type=provided type (e.g., OBJECT)
561547 entry . writeUInt8 ( 0 , 5 ) ; // st_other: Visibility=DEFAULT
562548 entry . writeUInt16LE ( sectionIdx , 6 ) ; // st_shndx: Index of the section containing this symbol
563- entry . writeBigUInt64LE ( BigInt ( ( _a = sym . offset ) !== null && _a !== void 0 ? _a : 0 ) , 8 ) ; // st_value: Relative offset *within* the section
564- entry . writeBigUInt64LE ( BigInt ( ( _b = sym . size ) !== null && _b !== void 0 ? _b : 0 ) , 16 ) ; // st_size: Size of the symbol data
549+ entry . writeBigUInt64LE ( BigInt ( sym . offset ?? 0 ) , 8 ) ; // st_value: Relative offset *within* the section
550+ entry . writeBigUInt64LE ( BigInt ( sym . size ?? 0 ) , 16 ) ; // st_size: Size of the symbol data
565551 finalEntries . push ( entry ) ;
566552 symbolIndexCounter ++ ; // Increment for the next symbol
567553 } ) ;
@@ -1152,7 +1138,6 @@ class HardwareCompiler {
11521138 const pltSection = this . sectionsRequired . has ( ".plt" /* SectionName.PLT */ ) ? this . getSection ( ".plt" /* SectionName.PLT */ ) : null ;
11531139 const gotPltSection = this . sectionsRequired . has ( ".got.plt" /* SectionName.GOT_PLT */ ) ? this . getSection ( ".got.plt" /* SectionName.GOT_PLT */ ) : null ;
11541140 this . relocations . forEach ( reloc => {
1155- var _a ;
11561141 if ( reloc . section !== ".text" /* SectionName.TEXT */ ) {
11571142 return ; // Only process .text relocations here
11581143 }
@@ -1214,7 +1199,7 @@ class HardwareCompiler {
12141199 throw new Error ( `Section name missing for local symbol ${ reloc . symbolName } ` ) ;
12151200 }
12161201 const targetSection = this . getSection ( symbolInfo . sectionName ) ;
1217- targetAddr = BigInt ( targetSection . address + ( ( _a = symbolInfo . offset ) !== null && _a !== void 0 ? _a : 0 ) ) ;
1202+ targetAddr = BigInt ( targetSection . address + ( symbolInfo . offset ?? 0 ) ) ;
12181203 // Formula: Target - (PatchLocation + 4) + Addend
12191204 value = Number ( targetAddr - ( patchAddr + BigInt ( 4 ) ) + addend ) ;
12201205 HardwareCompilerJournal . success ( 2 , ` Patching PC32 for ${ reloc . symbolName } : Offset=0x${ patchOffset . toString ( 16 ) } , PatchAddr=0x${ patchAddr . toString ( 16 ) } , Target=0x${ targetAddr . toString ( 16 ) } , Value=0x${ ( value >>> 0 ) . toString ( 16 ) } (${ value } )` ) ;
0 commit comments