Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(relay-server): statically linking libsqlite to relay binary and revert to using busybox as base image #3260

Open
sandeepnRES opened this issue May 14, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request rust Pull requests that update Rust code

Comments

@sandeepnRES
Copy link
Member

In PR #3001 , libsqlite was added to the relay module. But there were issues when statically linking libsqlite to the x86_64-unknown-linux-musl relay binary in relay image, so we used shared library libsqlite3.so. Now since busybox image being a minimalist docker image, a shared library can not be installed, hence we moved to using alpine image and installed sqlite-libs to dynamically link libsqlite3.so.

Expectation

But ideally we want to statically link libsqlite3.a to the relay binary and revert back to using minimalist busybox image. The dockerfile for the relay server: weaver/core/relay/Dockerfile.server.

Here is the diff of the change which can be useful when reverting back:
relay-server_3001_diff.txt

Issue with static linking

When trying to statically link libsqlite using libsqlite.a, and build relay docker image (before the PR changes, i.e. revert the attached diff changes, and add libsqlite.a as library in builder image), we get following error:

Error:

113.9   = note: /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `putVarint64':                                                              
113.9           (.text+0x75f): undefined reference to `__stack_chk_fail'                                                                                                 
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `pagerPagecount':                                                           
113.9           (.text+0xd9d): undefined reference to `__stack_chk_fail'                                                                                                 
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `databaseIsUnmoved':                                                        
113.9           (.text+0xe28): undefined reference to `__stack_chk_fail'                                                                                                 
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `btreeGetPage':                                                             
113.9           (.text+0x1102): undefined reference to `__stack_chk_fail'
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `vdbeSorterExtendFile':                                                     
113.9           (.text+0x161c): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x1707): more undefined references to `__stack_chk_fail' follow                   
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unixSleep':                                                                
113.9           (.text+0x74d3): undefined reference to `sleep'                                                                                                           
113.9           /usr/bin/ld: (.text+0x74e1): undefined reference to `usleep'                                                                                             
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `patternCompare':                                                           
113.9           (.text+0x7f0e): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3OsCurrentTimeInt64':                                                
113.9           (.text+0x8163): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `invokeProfileCallback':                                                    
113.9           (.text+0x8210): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `pthreadMutexFree':                                                         
113.9           (.text+0x8a65): undefined reference to `pthread_mutex_destroy'                                                                                           
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3GetVarint32':                                                       
113.9           (.text+0x91c2): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sessionSkipRecord':                                                        
113.9           (.text+0x927d): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unixAccess':                                                               
113.9           (.text+0x9433): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `pragmaVtabBestIndex':                                                      
113.9           (.text+0x9876): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `identPut':                                                                 
113.9           (.text+0x9b50): undefined reference to `__stack_chk_fail'                                                                                                
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0xa462): more undefined references to `__stack_chk_fail' follow                   
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `dotlockLock':                                                              
113.9           (.text+0x1495f): undefined reference to `utime'                                                                                                          
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3HashInsert':                                                        
113.9           (.text+0x153d9): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts3EvalDlPhraseNext':                                                     
113.9           (.text+0x15dcf): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts3PoslistPhraseMerge':                                                   
113.9           (.text+0x166c9): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts3EvalNearTrim':                                                         
113.9           (.text+0x16843): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3VdbePreUpdateHook':                                                 
113.9           (.text+0x16bab): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x17142): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `pthreadMutexAlloc':                                                        
113.9           (.text+0x1c3e6): undefined reference to `pthread_mutexattr_init'                                                                                         
113.9           /usr/bin/ld: (.text+0x1c3f3): undefined reference to `pthread_mutexattr_settype'                                                                         
113.9           /usr/bin/ld: (.text+0x1c3fe): undefined reference to `pthread_mutex_init'                                                                                
113.9           /usr/bin/ld: (.text+0x1c406): undefined reference to `pthread_mutexattr_destroy'                                                                         
113.9           /usr/bin/ld: (.text+0x1c45b): undefined reference to `pthread_mutex_init'                                                                                
113.9           /usr/bin/ld: (.text+0x1c480): undefined reference to `__stack_chk_fail'                           
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3IdListAppend':
113.9           (.text+0x1c8a9): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3_stmt_status':                                                      
113.9           (.text+0x1d228): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unixShmLock':                                                              
113.9           (.text+0x1ded2): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3PagerSetPagesize':                                                  
113.9           (.text+0x1e36d): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x1ebad): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `localtimeOffset':                                                          
113.9           (.text+0x276f3): undefined reference to `localtime_r'                                                                                                    
113.9           /usr/bin/ld: (.text+0x27778): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3Utf16to8.constprop.0':                                              
113.9           (.text+0x2782e): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3VdbeMakeReady':                                                     
113.9           (.text+0x27d7e): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3ExprImpliesNonNullRow':                                             
113.9           (.text+0x2a33b): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3ExprAnalyzeAggList':                                                
113.9           (.text+0x2a40b): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x2a556): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3VdbeMemStringify':                                                  
113.9           (.text+0x30a4a): undefined reference to `__memcpy_chk'                                                                                                   
113.9           /usr/bin/ld: (.text+0x30aae): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unicodeFunc':                                                              
113.9           (.text+0x31168): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `soundexFunc':                                                              
113.9           (.text+0x31799): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `vdbeCompareMemString':                                                     
113.9           (.text+0x3199e): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `printfFunc':                                                               
113.9           (.text+0x32026): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x33988): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `whereLoopAddOr':                                                           
113.9           (.text+0x495b9): undefined reference to `__memcpy_chk'                                                                                                   
113.9           /usr/bin/ld: (.text+0x4969a): undefined reference to `__memcpy_chk'                                                                                      
113.9           /usr/bin/ld: (.text+0x4987b): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `analyzeAggregate':                                                         
113.9           (.text+0x49b95): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3VdbeExplain':                                                       
113.9           (.text+0x4a09f): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `checkAppendMsg':                                                           
113.9           (.text+0x4a1ef): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `checkPtrmap':                                                              
113.9           (.text+0x4a2c2): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x4a5eb): more undefined references to `__stack_chk_fail' follow
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `balance_nonroot':
113.9           (.text+0x64c2e): undefined reference to `__memset_chk'                                                                                                   
113.9           /usr/bin/ld: (.text+0x64ca6): undefined reference to `__memset_chk'                                                                                      
113.9           /usr/bin/ld: (.text+0x65f4b): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `balance':                                                                  
113.9           (.text+0x66c74): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `clearDatabasePage':                                                        
113.9           (.text+0x66f78): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `accessPayload':                                                            
113.9           (.text+0x67452): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `btreeCreateTable':                                                         
113.9           (.text+0x67dfb): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x680cb): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts5Bm25Function':                                                         
113.9           (.text+0x718e7): undefined reference to `log'                                                                                                            
113.9           /usr/bin/ld: (.text+0x71974): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3Fts5Init':                                                          
113.9           (.text+0x7241a): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts5ParseTokenize':                                                        
113.9           (.text+0x734e9): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `fts3TokenizerFunc':                                                        
113.9           (.text+0x73e2f): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unixFullPathname':                                                         
113.9           (.text+0x744c7): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x74900): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `unixOpen':                                                                 
113.9           (.text+0x7b273): undefined reference to `__memcpy_chk'                                                                                                   
113.9           /usr/bin/ld: (.text+0x7b4eb): undefined reference to `__stack_chk_fail'                                                                                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sqlite3_load_extension':                                                   
113.9           (.text+0x7bb6e): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `loadExt':                                                                  
113.9           (.text+0x7bd08): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `sessionChangesetToHash':                                                   
113.9           (.text+0x7c753): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o): in function `jsonReturn.constprop.0':                                                   
113.9           (.text+0x7ce0e): undefined reference to `__stack_chk_fail'                                                                                               
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.text+0x7d1be): more undefined references to `__stack_chk_fail' follow                  
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.data.rel+0x38): undefined reference to `access'                                        
113.9           /usr/bin/ld: /usr/lib/x86_64-linux-musl/libsqlite3.a(sqlite3.o):(.data.rel+0xb0): undefined reference to `fcntl64'                                       
113.9           collect2: error: ld returned 1 exit status                                                                                                               
113.9                                                                                                                                                                    
113.9   = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified                                   
113.9   = note: use the `-l` flag to specify native libraries to link                                                                                                    
113.9   = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.
html#cargorustc-link-libkindname)
113.9 
113.9 warning: `relay` (bin "server") generated 16 warnings
113.9 error: could not compile `relay` (bin "server") due to previous error; 16 warnings emitted

Based on some internet search, tried adding RUSTFLAGS=-Clink-arg=-fstack-protector-strong and RUSTFLAGS=-Clink-arg=-fstack-protector-all (source) to the cargo build, but still the same error.

@sandeepnRES sandeepnRES added bug Something isn't working enhancement New feature or request rust Pull requests that update Rust code labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request rust Pull requests that update Rust code
Projects
None yet
Development

No branches or pull requests

1 participant