|  |  |  | # Check that the program works as expected without garble. | 
					
						
							|  |  |  | exec go build main.go | 
					
						
							|  |  |  | exec ./main | 
					
						
							|  |  |  | cmp stderr main.stderr | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # The default build includes DWARF and the symbol table. | 
					
						
							|  |  |  | [!windows] [exec:readelf] exec readelf --section-headers main$exe | 
					
						
							|  |  |  | [!windows] [exec:readelf] stdout 'debug_info' | 
					
						
							|  |  |  | [!windows] [exec:readelf] stdout '\.symtab' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # The default build includes full non-trimmed paths, as well as our names. | 
					
						
							|  |  |  | # Only check $WORK on non-windows, because it's difficult to do it there. | 
					
						
							|  |  |  | bingrep main$exe 'globalVar' 'globalFunc' | 
					
						
							|  |  |  | [!windows] bingrep main$exe ${WORK@R} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Check that we fail if the user forgot -trimpath. | 
					
						
							|  |  |  | ! exec go build -a -toolexec=garble main.go | 
					
						
							|  |  |  | stderr 'should be used alongside -trimpath' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Check that the simplest use of garble works. | 
					
						
							|  |  |  | exec go build -a -trimpath -toolexec=garble main.go | 
					
						
							|  |  |  | exec ./main | 
					
						
							|  |  |  | cmp stderr main.stderr | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [!windows] [exec:readelf] exec readelf --section-headers main$exe | 
					
						
							|  |  |  | [!windows] [exec:readelf] ! stdout 'debug_info' | 
					
						
							|  |  |  | [!windows] [exec:readelf] ! stdout '\.symtab' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! bingrep main$exe ${WORK@R} 'globalVar' 'globalFunc' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [short] stop # checking that the build is reproducible is slow | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Finally, check that the 'garble build' shortcut works, and produces the same | 
					
						
							|  |  |  | # binary. | 
					
						
							|  |  |  | cp main$exe main_old$exe | 
					
						
							|  |  |  | rm main$exe | 
					
						
							|  |  |  | garble build main.go | 
					
						
							|  |  |  | ! bingrep main$exe 'globalVar' | 
					
						
							|  |  |  | bincmp main$exe main_old$exe | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -- main.go -- | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var globalVar = "global value" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func globalFunc() { println("global func body") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	println(globalVar) | 
					
						
							|  |  |  | 	globalFunc() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | -- main.stderr -- | 
					
						
							|  |  |  | global value | 
					
						
							|  |  |  | global func body |