1f0697d7cSGreg Clayton""" 2f0697d7cSGreg ClaytonTest absolute symbols in ELF files to make sure they don't create sections and 3f0697d7cSGreg Claytonto verify that symbol values and size can still be accessed via SBSymbol APIs. 4f0697d7cSGreg Clayton""" 5f0697d7cSGreg Clayton 6f0697d7cSGreg Claytonfrom lldbsuite.test.decorators import * 7f0697d7cSGreg Claytonfrom lldbsuite.test.lldbtest import * 8f0697d7cSGreg Claytonfrom lldbsuite.test import lldbutil 9f0697d7cSGreg Claytonimport os 10f0697d7cSGreg Clayton 11f0697d7cSGreg Clayton 12*2238dcc3SJonas Devlieghereclass TestAbsoluteSymbol(TestBase): 13f0697d7cSGreg Clayton @no_debug_info_test 14f0697d7cSGreg Clayton def test_absolute_symbol(self): 15*2238dcc3SJonas Devlieghere """ 16f0697d7cSGreg Clayton Load an ELF file that contains two symbols: 17f0697d7cSGreg Clayton - "absolute" which is a symbol with the section SHN_ABS 18f0697d7cSGreg Clayton - "main" which is a code symbol in .text 19f0697d7cSGreg Clayton 20f0697d7cSGreg Clayton Index st_name st_value st_size st_info st_other st_shndx Name 21f0697d7cSGreg Clayton ======= ---------- ------------------ ------------------ ----------------------------------- -------- -------- =========================== 22f0697d7cSGreg Clayton [ 0] 0x00000000 0x0000000000000000 0x0000000000000000 0x00 (STB_LOCAL STT_NOTYPE ) 0x00 0 23f0697d7cSGreg Clayton [ 1] 0x00000001 0x0000000000001000 0x0000000000000004 0x12 (STB_GLOBAL STT_FUNC ) 0x00 1 main 24f0697d7cSGreg Clayton [ 2] 0x00000006 0xffffffff80000000 0x0000000000000009 0x10 (STB_GLOBAL STT_NOTYPE ) 0x00 SHN_ABS absolute 25f0697d7cSGreg Clayton 26f0697d7cSGreg Clayton We used to create sections for symbols whose section ID was SHN_ABS 27f0697d7cSGreg Clayton and this caused problems as the new sections could interfere with 28f0697d7cSGreg Clayton with address resolution. Absolute symbols' values are not addresses 29f0697d7cSGreg Clayton and should not be treated this way. 30f0697d7cSGreg Clayton 31f0697d7cSGreg Clayton New APIs were added to SBSymbol to allow access to the raw integer 32f0697d7cSGreg Clayton value and size of symbols so symbols whose value was not an address 33f0697d7cSGreg Clayton could be accessed. Prior to this commit, you could only call: 34f0697d7cSGreg Clayton 35f0697d7cSGreg Clayton SBAddress SBSymbol::GetStartAddress() 36f0697d7cSGreg Clayton SBAddress SBSymbol::GetEndAddress() 37f0697d7cSGreg Clayton 38f0697d7cSGreg Clayton If the symbol's value was not an address, you couldn't access the 39f0697d7cSGreg Clayton raw value because the above accessors would return invalid SBAddress 40f0697d7cSGreg Clayton objects if the value wasn't an address. New APIs were added for this: 41f0697d7cSGreg Clayton 42f0697d7cSGreg Clayton uint64_t SBSymbol::GetValue() 43f0697d7cSGreg Clayton uint64_t SBSymbol::GetSize(); 44*2238dcc3SJonas Devlieghere """ 45f0697d7cSGreg Clayton src_dir = self.getSourceDir() 46f0697d7cSGreg Clayton yaml_path = os.path.join(src_dir, "absolute.yaml") 47f0697d7cSGreg Clayton yaml_base, ext = os.path.splitext(yaml_path) 48f0697d7cSGreg Clayton obj_path = self.getBuildArtifact("a.out") 49f0697d7cSGreg Clayton self.yaml2obj(yaml_path, obj_path) 50f0697d7cSGreg Clayton 51f0697d7cSGreg Clayton # Create a target with the object file we just created from YAML 52f0697d7cSGreg Clayton target = self.dbg.CreateTarget(obj_path) 53f0697d7cSGreg Clayton self.assertTrue(target, VALID_TARGET) 54f0697d7cSGreg Clayton 55f0697d7cSGreg Clayton module = target.modules[0] 56f0697d7cSGreg Clayton 57f0697d7cSGreg Clayton # Make sure the 'main' symbol is valid and has address values. Also make 58f0697d7cSGreg Clayton # sure we can access the raw file address and size via the new APIS. 59*2238dcc3SJonas Devlieghere symbol = module.FindSymbol("main") 60f0697d7cSGreg Clayton self.assertTrue(symbol.IsValid()) 61f0697d7cSGreg Clayton self.assertTrue(symbol.GetStartAddress().IsValid()) 62f0697d7cSGreg Clayton self.assertTrue(symbol.GetEndAddress().IsValid()) 63f0697d7cSGreg Clayton self.assertEqual(symbol.GetValue(), 0x1000) 64f0697d7cSGreg Clayton self.assertEqual(symbol.GetSize(), 0x4) 65f0697d7cSGreg Clayton 66f0697d7cSGreg Clayton # Make sure the 'absolute' symbol is valid and has no address values. 67f0697d7cSGreg Clayton # Also make sure we can access the raw file address and size via the new 68f0697d7cSGreg Clayton # APIS. 69*2238dcc3SJonas Devlieghere symbol = module.FindSymbol("absolute") 70f0697d7cSGreg Clayton self.assertTrue(symbol.IsValid()) 71f0697d7cSGreg Clayton self.assertFalse(symbol.GetStartAddress().IsValid()) 72f0697d7cSGreg Clayton self.assertFalse(symbol.GetEndAddress().IsValid()) 73*2238dcc3SJonas Devlieghere self.assertEqual(symbol.GetValue(), 0xFFFFFFFF80000000) 74f0697d7cSGreg Clayton self.assertEqual(symbol.GetSize(), 9) 75f0697d7cSGreg Clayton 76f0697d7cSGreg Clayton # Make sure no sections were created for the absolute symbol with a 77f0697d7cSGreg Clayton # prefix of ".absolute." followed by the symbol name as they interfere 78f0697d7cSGreg Clayton # with address lookups if they are treated like real sections. 79f0697d7cSGreg Clayton for section in module.sections: 801fb5c7a2SDave Lee self.assertNotEqual(section.GetName(), ".absolute.absolute") 81