Analysis of the strings command Go and C++ compilation time a small difference

  • 2020-06-15 09:56:43
  • OfStack

Recently, I looked up an bug and analyzed it with the strings command. Unexpectedly, there was no result. I was very puzzled. Finally, the root cause of bug was found based on this clue.

1. In C++, even if the function is not called at the code level, it will eventually compile into base 2, which can be analyzed with strings.


#include <iostream>
using namespace std;
void fun()
{
    printf("hello world\n");  // strings Analysis yields results 
}
int main()
{
    return 0;
}

2. In Go, if the function is not called at the code level, or if it is optimized by the compiler when called, it will not be compiled into base 2, and information about the function will not be found with strings.


package main 
import "fmt" 
func test (a int){
 fmt.Println("testxxxxxx") // strings No result of analysis 
}
func main() { 
} 
package main 
import "fmt" 
func test (a int){
 a = 1
 if a != 1{
 fmt.Println("testxxxxxx")  //strings No result of analysis 
 }
}
func main() { 
 test(1)
} 

Take a look at


package main 
import "fmt" 
func test (a int){
 if a != 1{
 fmt.Println("testxxxxxx")  // strings Analysis yields results 
 }
}
func main() { 
 test(1)
} 

That's interesting. Pick 1 bug.

conclusion


Related articles: